试图为jenkins管道作业提供github凭据

时间:2017-04-02 19:57:46

标签: jenkins continuous-integration jenkins-pipeline

我试图在jenkins管道作业中设置github的凭据。我的管道脚本中有以下内容:

pipeline {
    agent any
    git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])

credentialsId来自哪里?这是在詹金斯的其他地方创造的吗?

更新: 我从此页面中提取了凭据ID: enter image description here

但现在我看到了这个错误:

  

由匿名用户启动   org.codehaus.groovy.control.MultipleCompilationErrorsException:   启动失败:WorkflowScript:3:未定义的部分" git" @第3行,   第5栏。

1 个答案:

答案 0 :(得分:1)

正如您自己发现的那样,它是凭据视图中提供的凭据ID。

现在,至于你的第二个问题,你正在使用声明性管道,它要求你有以下结构:

pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
            }
        }
    }
}

E.g。您需要放置gitstagesstage条款(documentation of this can be found here)的steps步骤。

或者您可以使用脚本化管道,然后它变为:

node {
    git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}

但是,当您创建简单的管道时,声明性管道提供了很多很好的功能。 See my answer here用于声明性和脚本化管道之间的比较。