Search code examples
gitlabgitlab-cigitlab-ce

Run a manual job from a multi-project pipeline


I have a pipeline that contains only manual jobs. Is it possible from within a multi-project pipeline to trigger this pipeline and tell it to run only some specific jobs? Like it would mimic a manual trigger.

Example:

My .gitlab-ci.yml (in myProject/Foo) file would look like this:

...

deploy_to_Production:
 <<: *job_deploy_definition
 stage: deploy
 when: manual
 variables:
    ENV: "Prod"
 only:
   refs:
     - tags

deploy_to_Integration:
 <<: *job_deploy_definition
 stage: deploy
 when: manual
 variables:
    ENV: "Int"

From the .gitlab-ci.yml file on my multi-project pipeline, I would like to trigger only one specific job:

...
production_deploy:
    stage: deploy
    trigger:
        project: myProject/Foo:deployToProduction # Is something like this possible ???
        #strategy: depend

Solution

  • If it's only deploy_to_Production that you want to trigger from that pipeline, you can split the job up slightly and use rules.

    The trigger pipeline:

    production_deploy:
      stage: deploy
      variables:
        DEPLOY_TO_PROD: true
      trigger:
        project: myProject/Foo
        #strategy: depend
    

    another trigger pipeline:

    integration_deploy:
      stage: deploy
      variables:
        DEPLOY_TO_INTEGRATION: true
      trigger:
        project: myProject/Foo
        #strategy: depend
    

    myProject/Foo:

    .deploy_to_Production:template:
     <<: *job_deploy_definition
     stage: deploy
     variables:
        ENV: "Prod"
    
    deploy_to_Production:manual:
     extends: .deploy_to_Production:template
     rules:
       - if: $CI_COMMIT_TAG
         when: manual
    
    deploy_to_Production:triggered:
     extends: .deploy_to_Production:template
     rules:
       - if: '$DEPLOY_TO_PROD == "true" && $CI_JOB_TRIGGERED == "true"'
    
    .deploy_to_Integration:template:
     <<: *job_deploy_definition
     stage: deploy
     variables:
        ENV: "Int"
    
    deploy_to_Integration:manual:
     extends: .deploy_to_Integration:template
     when: manual
    
    deploy_to_Integration:triggered:
     extends: .deploy_to_Integration:template
     rules:
       - if: '$DEPLOY_TO_INTEGRATION == "true" && $CI_JOB_TRIGGERED == "true"'