J'ai réalisé un projet de pipeline multibranches à Jenkins. J'ai besoin d'utiliser deux référentiels et les deux ont besoin d'informations d'identification.
J'ai créé un fichier Jenkins dans repository1:
node ('label1'){
stage 'sanity check'
sh 'echo sanity check'
stage 'checkout other repository'
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'https://[email protected]/BRNTZN/repository2.git'],[credentialsId:'23b2eed1-2863-49d5-bc7b-bcccb9ad914d']]
])
stage 'log results'
sh 'echo result = OK'
}
Lorsque je pousse ce fichier sur une branche de repository1 et démarre la génération, j'obtiens l'erreur suivante dans Jenkins:
Branch indexing
Setting Origin to https://[email protected]/BRNTZN/repository1.git
Fetching Origin...
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.Origin.url https://[email protected]/BRNTZN/repository1.git # timeout=10
Fetching upstream changes from https://[email protected]/BRNTZN/repository1.git
> git --version # timeout=10
using .gitcredentials to set credentials
> git config --local credential.username BRNTZN # timeout=10
> git config --local credential.helper store --file=/tmp/git1367320661933193799.credentials # timeout=10
> git -c core.askpass=true fetch --tags --progress https://[email protected]/BRNTZN/repository1.git +refs/heads/*:refs/remotes/Origin/*
> git config --local --remove-section credential # timeout=10
Checking out Revision d997a29e9d1f639d56eb425ec00e03309e099c7a (jenkinsfilebranch1)
> git config core.sparsecheckout # timeout=10
> git checkout -f d997a29e9d1f639d56eb425ec00e03309e099c7a
> git rev-list f81d0d366fd751857a2640c587817f4d047a15af # timeout=10
[Pipeline] node
Running on jenkins agent (i-07353fc08cb42f10e) in /var/jenkins/workspace/multiBranch/jenkinsfilebranch1
[Pipeline] {
[Pipeline] stage (sanity check)
Entering stage sanity check
Proceeding
[Pipeline] sh
[jenkinsfilebranch1] Running Shell script
+ echo sanity check
sanity check
[Pipeline] stage (checkout other repository)
Entering stage checkout other repository
Proceeding
[Pipeline] checkout
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.Origin.url https://[email protected]/BRNTZN/repository2.git # timeout=10
Fetching upstream changes from https://[email protected]/BRNTZN/repository2.git
> git --version # timeout=10
> git -c core.askpass=true fetch --tags --progress https://[email protected]/BRNTZN/repository2.git +refs/heads/*:refs/remotes/Origin/*
ERROR: Error fetching remote repo 'Origin'
hudson.plugins.git.GitException: Failed to fetch from https://[email protected]/BRNTZN/repository2.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.Java:799)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.Java:1055)
at hudson.plugins.git.GitSCM.checkout(GitSCM.Java:1086)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.Java:109)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.Java:83)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.Java:73)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.Java:52)
at hudson.security.ACL.impersonate(ACL.Java:213)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.Java:49)
at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:471)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: hudson.plugins.git.GitException: Command "git -c core.askpass=true fetch --tags --progress https://[email protected]/BRNTZN/repository2.git +refs/heads/*:refs/remotes/Origin/*" returned status code 128:
stdout:
stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://[email protected]/BRNTZN/repository2.git/'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.Java:1723)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.Java:1459)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.Java:63)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.Java:314)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.Java:152)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.Java:145)
at hudson.remoting.UserRequest.perform(UserRequest.Java:153)
at hudson.remoting.UserRequest.perform(UserRequest.Java:50)
at hudson.remoting.Request$2.run(Request.Java:332)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.Java:68)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
at Java.lang.Thread.run(Thread.Java:744)
at ......remote call to jenkins agent (i-07353fc08cb42f10e)(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.Java:1416)
at hudson.remoting.UserResponse.retrieve(UserRequest.Java:253)
at hudson.remoting.Channel.call(Channel.Java:781)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.Java:145)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:606)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.Java:131)
at com.Sun.proxy.$Proxy75.execute(Unknown Source)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.Java:797)
... 13 more
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: null
Finished: FAILURE
Les informations d'identification doivent être correctes:
Et l'utilisation de ces informations d'identification pour ce référentiel dans un projet freestyle ne donne aucune erreur:
Mise à jour
J'ai créé un projet de style libre en utilisant les informations d'identification SSH et j'ai ajouté cette clé publique à mon compte Bitbucket pour tester si je peux faire fonctionner SSH:
Cela a fonctionné:
Started by user admin
Building remotely on jenkins agent (i-039385e75b60d70f7) (label1) in workspace /var/jenkins/workspace/gitcredentials test
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.Origin.url [email protected]:BRNTZN/repository2.git # timeout=10
Fetching upstream changes from [email protected]:BRNTZN/repository2.git
> git --version # timeout=10
using GIT_SSH to set credentials jenkinsmaster key
> git -c core.askpass=true fetch --tags --progress [email protected]:BRNTZN/repository2.git +refs/heads/*:refs/remotes/Origin/*
> git rev-parse refs/remotes/Origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/Origin/origin/master^{commit} # timeout=10
Checking out Revision 1d51064143e7337cbc0b1910918166facc9c2330 (refs/remotes/Origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 1d51064143e7337cbc0b1910918166facc9c2330
First time build. Skipping changelog.
Finished: SUCCESS
Cependant lors de la mise à jour du fichier jenkins de la manière suivante:
node ('label1'){
stage 'sanity check'
sh 'echo sanity check'
stage 'checkout other repository'
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: '[email protected]:BRNTZN/repository2.git'],[credentialsId:'jenkinsmaster']]
])
stage 'log results'
sh 'echo result = OK'
}
Je reçois toujours la même erreur:
Started by user admin
Setting Origin to [email protected]:BRNTZN/repository1.git
Fetching Origin...
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.Origin.url [email protected]:BRNTZN/repository1.git # timeout=10
Fetching upstream changes from [email protected]:BRNTZN/repository1.git
> git --version # timeout=10
using GIT_SSH to set credentials jenkinsmaster key
> git -c core.askpass=true fetch --tags --progress [email protected]:BRNTZN/repository1.git +refs/heads/*:refs/remotes/Origin/*
Checking out Revision 29fc47911827d829f5abe9456bd8df78bc478fe7 (jenkinsfilebranch1)
> git config core.sparsecheckout # timeout=10
> git checkout -f 29fc47911827d829f5abe9456bd8df78bc478fe7
> git rev-list 29fc47911827d829f5abe9456bd8df78bc478fe7 # timeout=10
[Pipeline] node
Running on jenkins agent (i-039385e75b60d70f7) in /var/jenkins/workspace/multiBranch/jenkinsfilebranch1
[Pipeline] {
[Pipeline] stage (sanity check)
Entering stage sanity check
Proceeding
[Pipeline] sh
[jenkinsfilebranch1] Running Shell script
+ echo sanity check
sanity check
[Pipeline] stage (checkout other repository)
Entering stage checkout other repository
Proceeding
[Pipeline] checkout
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.Origin.url [email protected]:BRNTZN/repository2.git # timeout=10
Fetching upstream changes from [email protected]:BRNTZN/repository2.git
> git --version # timeout=10
> git -c core.askpass=true fetch --tags --progress [email protected]:BRNTZN/repository2.git +refs/heads/*:refs/remotes/Origin/*
ERROR: Error fetching remote repo 'Origin'
hudson.plugins.git.GitException: Failed to fetch from [email protected]:BRNTZN/repository2.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.Java:799)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.Java:1055)
at hudson.plugins.git.GitSCM.checkout(GitSCM.Java:1086)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.Java:109)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.Java:83)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.Java:73)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.Java:52)
at hudson.security.ACL.impersonate(ACL.Java:213)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.Java:49)
at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:471)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: hudson.plugins.git.GitException: Command "git -c core.askpass=true fetch --tags --progress [email protected]:BRNTZN/repository2.git +refs/heads/*:refs/remotes/Origin/*" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.Java:1723)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.Java:1459)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.Java:63)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.Java:314)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.Java:152)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.Java:145)
at hudson.remoting.UserRequest.perform(UserRequest.Java:153)
at hudson.remoting.UserRequest.perform(UserRequest.Java:50)
at hudson.remoting.Request$2.run(Request.Java:332)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.Java:68)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
at Java.lang.Thread.run(Thread.Java:744)
at ......remote call to jenkins agent (i-039385e75b60d70f7)(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.Java:1416)
at hudson.remoting.UserResponse.retrieve(UserRequest.Java:253)
at hudson.remoting.Channel.call(Channel.Java:781)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.Java:145)
at Sun.reflect.GeneratedMethodAccessor1180.invoke(Unknown Source)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:606)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.Java:131)
at com.Sun.proxy.$Proxy75.execute(Unknown Source)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.Java:797)
... 13 more
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: null
Finished: FAILURE
Votre instanciation de classe GitSCM est incorrecte. Vous avez créé deux objets UserRemoteConfig - un avec une URL de "[email protected]: BRNTZN/repository2.git" et un avec un identifiant de "jenkinsmaster". Au lieu de cela, vous voulez un objet avec les deux propriétés définies.
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: '[email protected]:BRNTZN/repository2.git'],[credentialsId:'jenkinsmaster']]
])
Devrait être:
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: '[email protected]:BRNTZN/repository2.git',credentialsId:'jenkinsmaster']]
])
Notez qu'il n'y a pas de crochets autour de la virgule dans la section "userRemoteConfigs" dans le deuxième cas.
Je venais de rencontrer le même problème et j'ai connecté un débogueur Eclipse à Jenkins pour trouver le problème.
J'ai eu exactement le même problème: le paiement à l'aide des informations d'identification dans un projet freestyle fonctionne correctement, le paiement dans un shell (en tant qu'utilisateur jenkins
) fonctionne correctement et le paiement dans le pipeline échoue. J'ai mis à jour les plugins Jenkins + vers la dernière version.
J'ai finalement réussi à le faire fonctionner en plaçant la bonne clé dans /var/lib/jenkins/.ssh/id_rsa. Il semble que le plugin GitSCM ignore complètement les informations d'identification fournies et utilise simplement la clé dans /var/lib/jenkins/.ssh/id_rsa
. J'ai généré une paire de clés sans mot de passe pour cela.
C'est une solution de contournement, et je soupçonne que GitSCM a un bogue, mais au moins vous pouvez utiliser le plugin de pipeline.
Quel type de références utilisez-vous?
Je vous suggère d'utiliser des informations d'identification SSH (c'est-à-dire des clés privées/publiques):
Ensuite, vous devez utiliser l'URL SSH comme connexion à votre Git vos informations d'identification dans votre pipeline (au lieu de l'URL HTTP), comme suit:
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url:'ssh://[email protected]:BRNTZN/repository2.git'],[credentialsId:'jenkins_ssh_key']]
])
Notez également que vous souhaiterez peut-être définir un identifiant spécifique pour vos informations d'identification (par exemple, jenkins_ssh_key
ou BRNTZN_ssh_key
) pour améliorer la lisibilité et simplifier la configuration du pipeline.
Comme indiqué dans Tutoriel du plugin Pipeline , pour un projet multibranches, vous n'avez pas besoin de spécifier le référentiel dans le nœud. Utilisez simplement checkout scm
.