-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major
-
Component/s: pipeline
Hi,
we discovered a bad behaviour when using a pipeline script which is getting loaded from an SCM.
Â
Scenario:
We have this simple Jenkins pipeline which is saved in a git repo (lets say https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git)
Â
Â
@Library('jenkinssharedlib') _ pipeline { agent { node { label 'master' customWorkspace "/tmp/workspace/${env.JOB_NAME}/${env.BUILD_NUMBER}" } } stages{ stage('Tagging Test') { steps { echo sh("git remote -v") echo sh("git show-ref") checkout([$class: 'GitSCM', branches: [[name: 'master' ]], userRemoteConfigs: [[credentialsId: 'hudstech-checkout-git', url: https://bitbucket.myserver/repositories/MyProject.git" ]]]) echo sh("git remote -v") echo sh("git show-ref") sh("git tag -a -m \"Tag lib1.0.0\" lib1.0.0") } } } }
Â
As you see above we are also using a shared library which is also in the same Git Repo as this Pipeline. This Git Repository contains a Tag called lib1.0.0
Â
In the Pipeline script we're trying to create a tag called lib1.0.0 in the checked out repository https://bitbucket.myserver/repositories/MyProject.git. Unfortunately it tells us the tag lib1.0.0 already exists because jenkins fetched the tag lib1.0.0 (and also all branches ...) from the Shared Library Repository.
Â
Here is what the pipeline output looks like:
Â
Obtained pipelines/testPipeline.groovy from git https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git Running in Durability level: MAX_SURVIVABILITY Loading library jenkinssharedlib@master Attempting to resolve master from remote references... > git --version # timeout=10 using GIT_ASKPASS to set credentials Github user for RW operations > git ls-remote -h https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10 Found match: refs/heads/master revision a4e28168cd1514b262a5de832090af5a14deea4a using credential hudstech-checkout-git > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10 Fetching without tags Fetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git --version # timeout=10 using GIT_ASKPASS to set credentials Github user for RW operations > git fetch --no-tags --progress https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git +refs/heads/master:refs/remotes/origin/master Checking out Revision a4e28168cd1514b262a5de832090af5a14deea4a (master) > git config core.sparsecheckout # timeout=10 > git checkout -f a4e28168cd1514b262a5de832090af5a14deea4a Commit message: "testPipeline" > git rev-list --no-walk a4e28168cd1514b262a5de832090af5a14deea4a # timeout=10 [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in XXX/workspace [Pipeline] { [Pipeline] ws Running in XXX/92 [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout using credential hudstech-checkout-git Cloning the remote Git repository Cloning repository https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git init XXX/92 # timeout=10 Fetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git --version # timeout=10 using GIT_ASKPASS to set credentials Github user for RW operations > git fetch --tags --progress https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git +refs/heads/*:refs/remotes/origin/* > git config remote.origin.url https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10 > git config remote.origin.url https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10 Fetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git using GIT_ASKPASS to set credentials Github user for RW operations > git fetch --tags --progress https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git +refs/heads/master:refs/remotes/origin/master > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 Checking out Revision a4e28168cd1514b262a5de832090af5a14deea4a (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f a4e28168cd1514b262a5de832090af5a14deea4a Commit message: "testPipeline" [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Tagging Test) [Pipeline] sh + git remote -v origin https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git (fetch) origin https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git (push) [Pipeline] echo null [Pipeline] sh + git show-ref 02f1b0773ae70b74ea73a5ffd1a8efbc5cb97aa7 refs/remotes/origin/GLSL-1679 e0e87cf929d1cb05516a36bb5a7ddb534ec3320f refs/remotes/origin/GLSL-1701 4fcdfb24ff67a804a8896de4444a2847b0ef38e7 refs/remotes/origin/deployBranch 0025f675e2212827a57cd500e74426475f59b906 refs/remotes/origin/dev 871fe0bf05eb1ab069bc15c0d1805ac8cae41520 refs/remotes/origin/feature/GLSL-1390 f2e5294499d73596e87c4fc17d9f9059a62e548d refs/remotes/origin/feature/refactoring 221921b700ddfbfbfc132b38ac58cce4bad44e23 refs/remotes/origin/gitflow a4e28168cd1514b262a5de832090af5a14deea4a refs/remotes/origin/master d47d9de8fc5df17d6668aa63d3a2053d823f92d9 refs/tags/lib1.0.0 [Pipeline] echo null [Pipeline] checkout using credential hudstech-checkout-git > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://bitbucket.myserver/repositories/MyProject.git # timeout=10 Fetching upstream changes from https://bitbucket.myserver/repositories/MyProject.git > git --version # timeout=10 using GIT_ASKPASS to set credentials Github user for RW operations > git fetch --tags --progress https://bitbucket.myserver/repositories/MyProject.git +refs/heads/*:refs/remotes/origin/* > git rev-parse origin/master^{commit} # timeout=10 Checking out Revision 3b236cdd354ebb0d637d138007cd676f7ba75e29 (origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 3b236cdd354ebb0d637d138007cd676f7ba75e29 Commit message: "XXX" > git rev-list --no-walk 3b236cdd354ebb0d637d138007cd676f7ba75e29 # timeout=10 [Pipeline] sh + git remote -v origin https://bitbucket.myserver/repositories/MyProject.git (fetch) origin https://bitbucket.myserver/repositories/MyProject.git (push) [Pipeline] echo null [Pipeline] sh + git show-ref 3047ce864ae0c40afc1445eab0b863cec362422d refs/remotes/origin/GLSL-1234 02f1b0773ae70b74ea73a5ffd1a8efbc5cb97aa7 refs/remotes/origin/GLSL-1679 e0e87cf929d1cb05516a36bb5a7ddb534ec3320f refs/remotes/origin/GLSL-1701 4fcdfb24ff67a804a8896de4444a2847b0ef38e7 refs/remotes/origin/deployBranch 6e5f04fc3cfa082a45fd6cf48dddc9c4899a5871 refs/remotes/origin/dev 871fe0bf05eb1ab069bc15c0d1805ac8cae41520 refs/remotes/origin/feature/GLSL-1390 f2e5294499d73596e87c4fc17d9f9059a62e548d refs/remotes/origin/feature/refactoring 221921b700ddfbfbfc132b38ac58cce4bad44e23 refs/remotes/origin/gitflow 3b236cdd354ebb0d637d138007cd676f7ba75e29 refs/remotes/origin/master 6e5f04fc3cfa082a45fd6cf48dddc9c4899a5871 refs/remotes/origin/test 6dc81e7df69d81d8bf86163d57b08ad88245e940 refs/remotes/origin/update b2760cb9d6dad7f50c9238e3eec827f9284a5913 refs/tags/1.0.0 1f48bba77b244fb947ce3b80dc7158def9f42ccb refs/tags/1.0.0-SNAPSHOT 507dc8d542e5dc4e13693a9a1718b867182ebdba refs/tags/1.0.2 bd14a5b4bde5f3fc56a6642dad5356c82624113d refs/tags/1.1.0 813a119062d7f0ae2cf467207f08c97625591042 refs/tags/1.1.1 e8db0e1bc384f84deb358d99bcfc3c4d1692c947 refs/tags/1.2.0 573a4173f1ec322ce339e0641a84386091eb2cd4 refs/tags/1.2.1 7a3d685bfdfcce8e20628e4dd5aa23b4360b792c refs/tags/1.2.1-1 32852d180c6f186d71b9f9e65e23e8562d8d3d8a refs/tags/1.2.1-2 aab43aad4b38d68673cc26ba1756abdd2cd60070 refs/tags/1.2.1-3 5b69912a8471181c5a7776a33f82cf9f134ebb3b refs/tags/1.2.1-4 f2b38551b2572bceb7456e23035d93f9eeecfc48 refs/tags/1.2.1-5 b8bce4b1f84fece5558f3fd7c0b71c4a9d4ddc0c refs/tags/1.2.1-6 f40bf5f34246d740ff1a3b79f67d72f6f9ff73ae refs/tags/1.2.1-7 926a9f013085762c3d206ea90534f5362793d8cb refs/tags/1.2.1-8 f1fb30f659e863d6f78720c0e4cf416b82206f11 refs/tags/1.2.1-9 4e24ba81219ef84721a5c4075d6b19cc46052d28 refs/tags/1.2.2 372f57fecdd186ab4ec51453ddfe9183578e7879 refs/tags/1.3.0 785a7d0f496d6930429bdd545bbfeedfce6d3543 refs/tags/1.4.0 d47d9de8fc5df17d6668aa63d3a2053d823f92d9 refs/tags/lib1.0.0 [Pipeline] echo null [Pipeline] script [Pipeline] { [Pipeline] withCredentials Masking supported pattern matches of $GIT_USERNAME or $GIT_PASSWORD [Pipeline] { [Pipeline] sh + git tag -a -m 'Tag lib1.0.0' lib1.0.0 fatal: tag 'lib1.0.0' already exists [Pipeline] } [Pipeline] // withCredentials [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // ws [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 128 Finished: FAILURE
Â
If we run the same Pipeline script by copy paste it into a Pipeline and not tell Jenkins to load it from an SCM it works perfectly. So it seems to be a problem with the Checkout from SCM in the Pipeline and maybe together with the fact that the Pipeline script is in the same git repository as the shared library?