Rules for a scheduled job does not work as expected
We have set our CI to create a pipeline on a push to a branch and set it to manual. There is also a configured schedule to run every hour. We want the scheduled pipeline to be started only if there is a change in the code since the last time the pipeline was executed. The way we tried to implement this is by comparing the commit sha.
The way the CI is configured is to use rules
rules: - if: $CI_COMMIT_BRANCH == "Active_Development" && $CI_PIPELINE_SOURCE == "push" when: manual - if: $CI_COMMIT_SHA != $LAST_SHA && $CI_COMMIT_BRANCH == "Active_Development" && $CI_PIPELINE_SOURCE == "schedule" when: on_success - when: never
$LAST_SHA variable is extracted from the pipeline API →
curl -s --header "PRIVATE-TOKEN: $TOKEN" "$GITLAB/api/v4/projects/54670/pipelines?per_page=3&&sort=desc" |jq -c '. | .sha' | sed -e 's/^"//' -e 's/"$//'
This rule is added to all jobs and stages.
The problem is that the schedule is creating a pipeline every hour no matter that the $CI_COMMIT_SHA is equal to the value of $LAST_SHA
- GitLab Enterprise Edition 13.2.10-ee*
The idea is the following:
- Pipeline #1950986 is started by the scheduler and executed successfully
- Code to Actvive_Development branch has been pushed and pipeline #1951087 has been created and set to manual
- Pipeline #1951088 is started by the scheduler and executed successfully (compare the $CI_COMMIT_SHA - 4bc27a6 with the $LAST_SHA - 7f2910b9 and if different create the pipeline)
- Pipeline #1951110 is started and it fails because of the same docker manifest ( it should not start as the $CI_COMMIT_SHA - 4bc276a6 is the same as $LAST_SHA - 4bc276a6 )
Can you give an advise how to make this work