| 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.gitObtained pipelines/testPipeline.groovy from git https://bitbucket.myserver/repositories/jenkinsSharedLibrary.gitRunning in Durability level: MAX_SURVIVABILITYLoading library jenkinssharedlib@masterAttempting to resolve master from remote references... > git --version # timeout=10using GIT_ASKPASS to set credentials Github user for RW operations > git ls-remote -h https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10Found match: refs/heads/master revision a4e28168cd1514b262a5de832090af5a14deea4ausing credential hudstech-checkout-git > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git # timeout=10Fetching without tagsFetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git --version # timeout=10using 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/masterChecking out Revision a4e28168cd1514b262a5de832090af5a14deea4a (master) > git config core.sparsecheckout # timeout=10 > git checkout -f a4e28168cd1514b262a5de832090af5a14deea4aCommit message: "testPipeline" > git rev-list --no-walk a4e28168cd1514b262a5de832090af5a14deea4a # timeout=10[Pipeline] Start of Pipeline[Pipeline] nodeRunning on Jenkins in XXX/workspace[Pipeline] {[Pipeline] wsRunning in XXX/92[Pipeline] {[Pipeline] stage[Pipeline] { (Declarative: Checkout SCM)[Pipeline] checkoutusing credential hudstech-checkout-gitCloning the remote Git repositoryCloning repository https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git init XXX/92 # timeout=10Fetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git > git --version # timeout=10using 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=10Fetching upstream changes from https://bitbucket.myserver/repositories/jenkinsSharedLibrary.gitusing 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=10Checking out Revision a4e28168cd1514b262a5de832090af5a14deea4a (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f a4e28168cd1514b262a5de832090af5a14deea4aCommit message: "testPipeline"[Pipeline] }[Pipeline] // stage[Pipeline] withEnv[Pipeline] {[Pipeline] stage[Pipeline] { (Tagging Test)[Pipeline] sh+ git remote -vorigin https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git (fetch)origin https://bitbucket.myserver/repositories/jenkinsSharedLibrary.git (push)[Pipeline] echonull[Pipeline] sh+ git show-ref02f1b0773ae70b74ea73a5ffd1a8efbc5cb97aa7 refs/remotes/origin/GLSL-1679e0e87cf929d1cb05516a36bb5a7ddb534ec3320f refs/remotes/origin/GLSL-17014fcdfb24ff67a804a8896de4444a2847b0ef38e7 refs/remotes/origin/deployBranch0025f675e2212827a57cd500e74426475f59b906 refs/remotes/origin/dev871fe0bf05eb1ab069bc15c0d1805ac8cae41520 refs/remotes/origin/feature/GLSL-1390f2e5294499d73596e87c4fc17d9f9059a62e548d refs/remotes/origin/feature/refactoring221921b700ddfbfbfc132b38ac58cce4bad44e23 refs/remotes/origin/gitflowa4e28168cd1514b262a5de832090af5a14deea4a refs/remotes/origin/masterd47d9de8fc5df17d6668aa63d3a2053d823f92d9 refs/tags/lib1.0.0[Pipeline] echonull[Pipeline] checkoutusing credential hudstech-checkout-git > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url https://bitbucket.myserver/repositories/MyProject.git # timeout=10Fetching upstream changes from https://bitbucket.myserver/repositories/MyProject.git > git --version # timeout=10using 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=10Checking out Revision 3b236cdd354ebb0d637d138007cd676f7ba75e29 (origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 3b236cdd354ebb0d637d138007cd676f7ba75e29Commit message: "XXX" > git rev-list --no-walk 3b236cdd354ebb0d637d138007cd676f7ba75e29 # timeout=10[Pipeline] sh+ git remote -vorigin https://bitbucket.myserver/repositories/MyProject.git (fetch)origin https://bitbucket.myserver/repositories/MyProject.git (push)[Pipeline] echonull[Pipeline] sh+ git show-ref3047ce864ae0c40afc1445eab0b863cec362422d refs/remotes/origin/GLSL-123402f1b0773ae70b74ea73a5ffd1a8efbc5cb97aa7 refs/remotes/origin/GLSL-1679e0e87cf929d1cb05516a36bb5a7ddb534ec3320f refs/remotes/origin/GLSL-17014fcdfb24ff67a804a8896de4444a2847b0ef38e7 refs/remotes/origin/deployBranch6e5f04fc3cfa082a45fd6cf48dddc9c4899a5871 refs/remotes/origin/dev871fe0bf05eb1ab069bc15c0d1805ac8cae41520 refs/remotes/origin/feature/GLSL-1390f2e5294499d73596e87c4fc17d9f9059a62e548d refs/remotes/origin/feature/refactoring221921b700ddfbfbfc132b38ac58cce4bad44e23 refs/remotes/origin/gitflow3b236cdd354ebb0d637d138007cd676f7ba75e29 refs/remotes/origin/master6e5f04fc3cfa082a45fd6cf48dddc9c4899a5871 refs/remotes/origin/test6dc81e7df69d81d8bf86163d57b08ad88245e940 refs/remotes/origin/updateb2760cb9d6dad7f50c9238e3eec827f9284a5913 refs/tags/1.0.01f48bba77b244fb947ce3b80dc7158def9f42ccb refs/tags/1.0.0-SNAPSHOT507dc8d542e5dc4e13693a9a1718b867182ebdba refs/tags/1.0.2bd14a5b4bde5f3fc56a6642dad5356c82624113d refs/tags/1.1.0813a119062d7f0ae2cf467207f08c97625591042 refs/tags/1.1.1e8db0e1bc384f84deb358d99bcfc3c4d1692c947 refs/tags/1.2.0573a4173f1ec322ce339e0641a84386091eb2cd4 refs/tags/1.2.17a3d685bfdfcce8e20628e4dd5aa23b4360b792c refs/tags/1.2.1-132852d180c6f186d71b9f9e65e23e8562d8d3d8a refs/tags/1.2.1-2aab43aad4b38d68673cc26ba1756abdd2cd60070 refs/tags/1.2.1-35b69912a8471181c5a7776a33f82cf9f134ebb3b refs/tags/1.2.1-4f2b38551b2572bceb7456e23035d93f9eeecfc48 refs/tags/1.2.1-5b8bce4b1f84fece5558f3fd7c0b71c4a9d4ddc0c refs/tags/1.2.1-6f40bf5f34246d740ff1a3b79f67d72f6f9ff73ae refs/tags/1.2.1-7926a9f013085762c3d206ea90534f5362793d8cb refs/tags/1.2.1-8f1fb30f659e863d6f78720c0e4cf416b82206f11 refs/tags/1.2.1-94e24ba81219ef84721a5c4075d6b19cc46052d28 refs/tags/1.2.2372f57fecdd186ab4ec51453ddfe9183578e7879 refs/tags/1.3.0785a7d0f496d6930429bdd545bbfeedfce6d3543 refs/tags/1.4.0d47d9de8fc5df17d6668aa63d3a2053d823f92d9 refs/tags/lib1.0.0[Pipeline] echonull[Pipeline] script[Pipeline] {[Pipeline] withCredentialsMasking supported pattern matches of $GIT_USERNAME or $GIT_PASSWORD[Pipeline] {[Pipeline] sh+ git tag -a -m 'Tag lib1.0.0' lib1.0.0fatal: 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 PipelineERROR: script returned exit code 128Finished: 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? |