-
Bug
-
Resolution: Unresolved
-
Trivial
-
Jenkins Version 2.462.1;
Git plugin Version 5.5.2 ;
Git client plugin Version 5.0.0 ;
Overview:
We have Jenkins Pipeline Job where it uses different Agents for consecutive Stages;
The job is configured to use `Pipeline script from SCM` and uses `master` as a branch.
When job starts it checks out latest `master` on Master Node, and then checks code again on every new Agent.
If `master` branch is updated after job started - it will check out newer commits on the Agents.
So at the end job will start at commit AAA but if any new BBB commit is merged while the job runs - consecutive stages that run on separate Agents will checkout BBB which would lead to incorrect results from the job.
Steps to repro:
- Create Jenkins Pipeline Job:
- configure its Jenkinsfile with global `agent none` and have 2 stages with different Agents;
- in SCM settings of the Job configure it to watch over a branch
- add sleep to 1st stage so there will be time to merge new commit into the branch
- Start the job
- While the job runs but before 2nd stage(while 1st stage sleeps) merge new commit to the branch
Actual result
Observe that 2nd stage would checkout the branch but with newest commit (merged in step3 above)
Expected result
2nd stage checks out same commit as was checked out on the job start
Workaround:
save GIT_COMMIT at the job start (at the beginning of the 1st stage), and use this saved commit to explicitly checkout on all the consecutive Stages that run on separate Jenkins Agents:
checkout scmGit(branches: [[name: "${saved_git_commit}"]], extensions: [], userRemoteConfigs: [[credentialsId: 'gerrit-cred', url: "${saved_git_url}"]])