【问题标题】:Jenkins Pipeline based on groovy : unable to push to the git: Permission denied (publickey)基于groovy的Jenkins Pipeline:无法推送到git:权限被拒绝(公钥)
【发布时间】:2018-08-01 09:54:44
【问题描述】:

我正在尝试使用 groovy 管道语法将一些更改推送到 git 存储库。但我无法推动。谁能帮帮我。

管道语法:

        sh '''
        #git checkout pkg_version
        touch README
        git add .
        git status
        git commit -m "Updated Package Version"
        git remote -v
        sshagent(credentialsId) {
            git push origin pkg_version
        }
        #git push origin pkg_version
        '''

詹金斯错误:

origin  ssh://jenkins@gerrit:29418/sfdx_nar (fetch)
origin  ssh://jenkins@gerrit:29418/sfdx_nar (push)
+ git push origin pkg_version
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[Pipeline] }  

【问题讨论】:

  • 您是否尝试过使用同一台机器上的 Jenkins 用户推送任何内容?意味着 SSH 到 Jenkins 从机并使用 Jenkins 用户进行推送?
  • 是的,我使用 Jenkins 用户(服务帐户)推送
  • 在没有采用它的情况下在该机器上运行时你的 sh 脚本是否工作?在我看来,您似乎是在尝试从 shell 脚本中调用管道步骤“sshagent”。
  • 是的,它正在使用普通的 git 命令。是的,我正在尝试在脚本中调用

标签: jenkins groovy jenkins-pipeline groovyshell jenkins-groovy


【解决方案1】:

尝试在您的管道中使用这样的 SSHAgent:

steps{
  sshagent(['your-credential-id']) {
    sh "git-steps..."
  }
}

【讨论】:

  • 感谢您的回复,上述语法出现错误: [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withCredentials [Pipeline] } [Pipeline] / / node [Pipeline] End of Pipeline java.lang.NoSuchMethodError: 在 dockerFingerprintFrom、dockerFingerprintRun、echo、emailext、emailextrecipients、viewsTabBar、weather、zfs、zip] 或 globals [currentBuild、docker、env 等步骤中找不到此类 DSL 方法“步骤” , fileLoader, params, scm] at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:149)
猜你喜欢
  • 2014-02-01
  • 1970-01-01
  • 2013-02-28
  • 2015-02-12
  • 2018-10-24
  • 2014-03-18
  • 1970-01-01
  • 2017-12-18
  • 1970-01-01
相关资源
最近更新 更多