How do I establish manual stages in Gitlab CI?
Asked Answered
P

4

41

I'd can't seem to find any documentation of manual staging in Gitlab CI in version 8.9. How do I do a manual stage such as "Deploy to Test"?

I'd like Gitlab CI to deploy a successful RPM to dev, and then once I've reviewed it, push to Test, and from there generate a release. Is this possible with Gitlab CI currently?

Petronella answered 9/8, 2015 at 13:22 Comment(0)
W
62

You can set tasks to be manual by using when: manual in the job (documentation).

So for example, if you want to want the deployment to happen at every push but give the option to manually tear down the infrastructure, this is how you would do it:

stages:
  - deploy
  - destroy

deploy:
  stage: deploy
  script:
    - [STEPS TO DEPLOY]

destroy:
  stage: destroy
  script:
    - [STEPS TO DESTROY]
  when: manual

With the above config, if you go to the GitLab project > Pipelines, you should see a play button next to the last commit. When you click the play button you can see the destroy option.

Winebibber answered 12/12, 2018 at 10:39 Comment(1)
Is there a way to mark the whole stage to be manual, so that I don't have to add when: manual to each job? Even better, is there a flag that makes it so that every job in the pipeline must be manually triggered? Would be nice to have something like that which could be enabled temporarily for testing, but I can't find anything built-in like that in the docs.Nebulose
C
10

Update: Manual actions were Introduced in GitLab 8.10. From the manual "Manual actions are a special type of job that are not executed automatically; they need to be explicitly started by a user. Manual actions can be started from pipeline, build, environment, and deployment views. You can execute the same manual action multiple times." An example usage of manual actions is deployment to production. The rest of this answer applies to Gitlab 8.9 and older only.

Historical Answer:

It does not appear as though manual deploy/release was available in Gitlab in 8.9.

One possibility is to have a protected branch which triggers a release. See info about protected branches here: http://doc.gitlab.com/ce/workflow/protected_branches.html

Essentially a protected branch would allow you to Create a branch (testdeploybranch) which only you would be allowed to merge code into. Whenever a commit to dev would pass the Gitlab CI tests and deploy jobs, as well as your manual review, you could merge that commit into the protected branch to trigger the release. For this branch you can then set up a special release job in Gitlab CI using the only option in the .gitlab-ci.yml job definition. Read more here: http://doc.gitlab.com/ci/yaml/README.html

So something like this:

release:
  only: testdeploybranch
  type: release
  script: some command or script invocation to deploy to Test

This might not be exactly what you are after, but it does allow you to do manual releases from Gitlab. It does not provide an easy way to manually do the same release procedure manually for different servers. Perhaps someone else might be able to expand on this strategy.

Cyclamate answered 18/8, 2015 at 11:33 Comment(4)
I'm going to let the flavour simmer on this one for 48 hours, however it's likely to become the accepted answer. It's not as nice as clicking a button in Bamboo.. But pushing to a specific branch isn't that difficult. Gitlab-CI should add a manual trigger option to the build jobs.Petronella
As for the bit about deploying the same release on multiple servers, I'd likely just deposit the release on a share/artifactory/archiva server and trigger puppet/saltstack deployment from there. Another option might be a snapshot branch, and a release branch. Pushing to snapshot generates a snapshot that is deployed to test, and then if that passes a push to release is made, which schedules deployment to prod.Petronella
[Manual actions][1] were introduced in GitLab 8.10. [1]: docs.gitlab.com/ce/ci/yaml/README.html#manual-actionsLithograph
Thank you Warren for updating the answer.Cyclamate
L
5

Finally, we have Gitlab CI manual actions that were introduced in GitLab 8.10.

Lithograph answered 21/8, 2016 at 11:18 Comment(1)
Correct URL is docs.gitlab.com/ce/ci/yaml/README.html#whenmanualCrandell
A
0
stages:
  - deploy_dev
  - deploy_test
  - release
deploy_dev:
  stage: deploy_dev
  script:
    - echo "Deploying to Dev environment..."
    - ./deploy_to_dev.sh #deployment script
  only:
    - master
deploy_test:
  stage: deploy_test
  script:
    - echo "Deploying to Test environment..."
    - ./deploy_to_test.sh #deployment script
  when: manual
  only:
    - master
Alcheringa answered 13/6 at 20:49 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Buckeye

© 2022 - 2024 — McMap. All rights reserved.