2016-08-30 11 views
6

में कोड की जांच नहीं कर सकता है मेरी जेनकींस पाइपलाइन प्रोजेक्ट में मैं गिट ठीक से कोड देख सकता हूं ... लेकिन हमें कुछ गिट चेकइन करने की आवश्यकता है और प्रमाण-पत्र स्पष्ट रूप से कैश नहीं किए गए हैं।जेनकिंस पाइपलाइन गिट

Entering stage Checkout 
Proceeding 
[Pipeline] git 
> git rev-parse --is-inside-work-tree # timeout=10 
Fetching changes from the remote Git repository 
> git config remote.origin.url [email protected]:myproj # timeout=10 
Fetching upstream changes from [email protected]:myproj.git 
> git --version # timeout=10 
using GIT_SSH to set credentials 
> git -c core.askpass=true fetch --tags --progress [email protected]:myproj.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 cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 (refs/remotes/origin/master) 
> git config core.sparsecheckout # timeout=10 
> git checkout -f cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 # timeout=10 
> git branch -a -v --no-abbrev # timeout=10 
> git branch -D master # timeout=10 
> git checkout -b master cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 
> git rev-list cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 # timeout=10 
[Pipeline] sh 
[myproj] Running shell script 
+ git push --set-upstream origin master 
Warning: Permanently added the RSA host key for IP address '192.192.143.2' to the list of known hosts. 
Permission denied (publickey). 
fatal: Could not read from remote repository. 

किसी को भी इस के लिए एक अच्छा समाधान है:

stage 'Checkout' 
    git url: '[email protected]:myproj.git', branch: 'master', credentialsId: '012ce21d-e920-44ee-b6f7-08df8ab41de0', variable: 'CREDENTIALS' 
    sh('git push') <---- fails with Permission denied (public key). 
यहाँ

नमूना उत्पादन है?

धन्यवाद

+0

आप डोकर से बाहर जेनकींस उपयोग कर रहे हैं? –

+0

दासों में चलने वाले दास, ऐसा नहीं लगता कि –

+0

के मामले में मुझे हाल ही में विंडोज गुलामों पर एक ही समस्या थी ... बस यह सुनिश्चित करने के लिए, क्या आप इसे अपने पाइपलाइन का परिणाम बता सकते हैं यदि आप इसे मास्टर से चलाते हैं? साथ ही, क्या आपने सही भंडार अनुमतियों को कॉन्फ़िगर किया है? आपके गिट @ गिटबकेट यूआरएल से यह कहता है कि एक गिट उपयोगकर्ता को आपके रेपो – Pom12

उत्तर

2

जवाब sshagent जेनकींस प्लगइन का उपयोग करने के लिए है:

http://getmesh.io/Blog/Jenkins+2+Pipeline+101

इस प्लगइन Git पहुँच

+0

पर सही पहुंच होनी चाहिए मुझे नहीं लगता कि यह "जवाब" है। यह एक कामकाज है लेकिन आपको ऐसा करने के लिए sshagent की आवश्यकता नहीं है, मैं व्यक्तिगत रूप से मेरे पाइपलाइन में 'sshagent' कमांड नहीं है और' गिट पुश 'ठीक काम कर रहा है। हालांकि मेरे पास जेनकींस होम ('/ var/lib/jenkins/.ssh/id_rsa') में संबंधित निजी कुंजी है और संबंधित क्रेडेंशियल्स 'jenkins_ssh_key' जो इस निजी कुंजी को इंगित करता है ... – Pom12

+0

दास पर वह निर्देशिका है? –

+0

हाँ मेरे पास दास और गुरु दोनों पर है और दोनों ठीक काम कर रहे हैं! – Pom12

4

जेनकींस पाइपलाइन नमूने भंडार से निकाले के लिए एक SSH_AUTH_SOCK वातावरण चर इंजेक्शन, हम ऐसा कर सकते हैं जो sshagent का उपयोग करने से बचें: https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/push-git-repo/pushGitRepo.Groovy

फिर अपने उदाहरण के लिए, समाधान साख बंधन प्लगइन (https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin) का उपयोग किया जाना चाहिए और इस स्निपेट का उपयोग:

stage ('Checkout') { 
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '012ce21d-e920-44ee-b6f7-08df8ab41de0', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { 
    sh("git tag -a some_tag -m 'Jenkins'") 
    sh('git push git://${GIT_USERNAME}:${GIT_PASSWORD}@bitbucket.org:myproj.git') 
    } 
} 
संबंधित मुद्दे