正在尝试向 jenkins 管道作业提供 github 凭据
Attempting to provide github credentials to jenkins pipeline job
我正在尝试在 jenkins 管道作业中为 github 设置凭据。我的管道脚本中有以下内容:
pipeline {
agent any
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
credentialsId 来自哪里?这是在 Jenkins 的其他地方创建的吗?
更新:
我从此页面中提取了凭据 ID:
但现在我看到了这个错误:
Started by user anonymous
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: WorkflowScript: 3: Undefined section "git" @ line 3,
column 5.
如您所见,它是凭据视图中提供的凭据 ID。
现在,关于你的第二个问题,你使用的是声明式管道,它要求你具有以下结构:
pipeline {
agent any
stages {
stage('Example') {
steps {
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}
}
}
}
例如您需要将 git
步骤插入 stages
、stage
和 steps
子句 (documentation of this can be found here).
或者你可以使用脚本管道,然后它变成:
node {
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}
但是,当您创建简单的管道时,声明式管道会提供很多不错的功能。 声明式和脚本化管道之间的比较。
我正在尝试在 jenkins 管道作业中为 github 设置凭据。我的管道脚本中有以下内容:
pipeline {
agent any
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
credentialsId 来自哪里?这是在 Jenkins 的其他地方创建的吗?
更新:
我从此页面中提取了凭据 ID:
但现在我看到了这个错误:
Started by user anonymous org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 3: Undefined section "git" @ line 3, column 5.
如您所见,它是凭据视图中提供的凭据 ID。
现在,关于你的第二个问题,你使用的是声明式管道,它要求你具有以下结构:
pipeline {
agent any
stages {
stage('Example') {
steps {
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}
}
}
}
例如您需要将 git
步骤插入 stages
、stage
和 steps
子句 (documentation of this can be found here).
或者你可以使用脚本管道,然后它变成:
node {
git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}
但是,当您创建简单的管道时,声明式管道会提供很多不错的功能。