Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab ci: Run build job when manual or when master only

Is it possible to have a gitlab-ci file wheres a build job defined with the following requirements:

  • get executed when manual OR
  • get executed by master push

I thought of something like this, but this is poorly false:

build_jar: stage: build script:   - echo "build jar" artifacts:   paths:     - jar/path/*.jar only:   - master when: manual 

Only solution for me is to have two jobs, one for the master push and one a manual input. But the disadvantage is, that in gitlab it becomes confusingly

like image 639
toni_maccaroni Avatar asked Dec 05 '17 10:12

toni_maccaroni


People also ask

What is manual job in GitLab?

In GitLab CI/CD you can easily configure a job to require manual intervention before it runs. The job gets added to the pipeline, but doesn't run until you click the play button on it. Notice that the manual job gets skipped, and the pipeline completes successfully even though the manual job did not get triggered.

Which GitLab keyword is used to make sure the job doesn't run automatically?

To configure a job to be executed only when the pipeline has been scheduled, use the rules keyword.

Do GitLab jobs run in parallel?

Fortunately, GitLab CI provides an easy way to run a job in parallel using the parallel keyword. In the background, this creates "clones" of the same job, so that multiple copies of it can run simultaneously.


1 Answers

I also did not find a way to do this in one block and had to use yaml anchors and split into two separate blocks:

.deploy_common: # common config HERE  deploy_master_CD:   extends: .deploy_common   only:     refs:       - master  deploy_manual:   extends: .deploy_common   when: manual 

OR all in one since GitLab 12.3 using rules

deploy:   rules:     - if: '$CI_COMMIT_REF_NAME == "master"'     - when: manual 
like image 178
lukmdo Avatar answered Nov 10 '22 10:11

lukmdo