I have a little problem with my GitLab pipeline.
I would like to run a manual job with scheduled rule or find a way to run a scheduled pipe with my jobs without rewrite the pipe.
As you see in the example I have 2 firstjob tagged job. One is manually and one is scheduled. My problem that if I run the scheduled workflow, the AC-test won't start and if I try to run the FirstJob by scheduled rule, it won't start because of when: manual
section.
Here is my example:
stages:
- firstjob
- test
- build
- deploy
FirstJob:
stage: firstjob
script:
- echo "Hello Peoples!"
- sleep 1
when: manual
allow_failure: false
FirstJobSchedule:
stage: firstjob
script:
- echo "Hello Scheduled Peoples!"
- sleep 1
only:
- schedule
allow_failure: false
AC-test:
needs: [FirstJob]
stage: test
script:
- echo "AC Test is running"
- sleep 10
ProdJobBuild:
stage: build
needs: [AC-test]
script:
- echo "Building thing to prod"
ProdJobDeploy:
stage: deploy
needs: [ProdJobBuild]
script:
- echo "Deploying thing to prod"
There's a way to do that with only:
, but I'd suggest moving to rules:
as only:
is going to be deprecated.
So you will not need two jobs with different conditions, you can do a branching condition:
stages:
- firstjob
- test
- build
- deploy
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
FirstJob:
stage: firstjob
script:
- echo "Hello Peoples!"
- sleep 1
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
# when: always # is a default value
- when: manual
# allow_failure: false # is a default value
AC-test:
needs: [FirstJob]
stage: test
script:
- echo "AC Test is running"
- sleep 10
ProdJobBuild:
stage: build
needs: [AC-test]
script:
- echo "Building thing to prod"
With it, the pipeline checks if the job is called by a schedule, and runs.
And if not, stays manual
.
*I took the freedom to pick the MR-style of workflow to avoid the double pipelines.