我有一個 Jenkins 管道在兩個節點上并行運行兩個測驗,例如:
pipeline
{
agent { label 'MASTER' }
stages
{
stage('x86 and Arm tests')
{
parallel
{
stage('x86')
{
agent
{
label ('x86')
}
steps
{
sh "something"
}
}
stage('arm')
{
agent
{
label ('arm')
}
steps
{
sh "something"
}
}
}
}
}
}
問題在于 GitHub 憑據:我需要為兩個測驗(x86 機器與 Arm 機器)提供兩個不同的 GitHub 憑據。
目前我已經將我的作業配置為通過 x86 機器的 SSH 密鑰進行身份驗證。但是這個鍵似乎不適用于 Arm 作業。
如何告訴 Jenkinspipeline在stage?
處理憑據。
uj5u.com熱心網友回復:
從 SCM 運行宣告性管道時,對于執行期間使用的每個代理,用于加載管道的存盤庫將自動檢出到作業區。
如果要更改此默認行為并手動控制每個代理的 SCM 配置,您必須首先使用skipDefaultCheckout選項禁用該行為。
skipDefaultCheckout
默認情況下,在 agent 指令中跳過從源代碼管理中檢出代碼。
例如:options { skipDefaultCheckout() }
然后在每個代理中,您應該使用所需的引數(如分支、存盤庫 URL 和憑據)檢查您的存盤庫。為此,您可以使用通用結帳步驟,也可以使用其他 SCM 特定步驟,例如git步驟,它是更強大結帳步驟子集的簡化簡寫。
如果在其中一個代理上,您想要使用用于獲取管道腳本的相同配置(如默認行為),您可以使用checkout scm.
這是一個帶有多個選項的示例:
pipeline {
agent any
options {
skipDefaultCheckout()
}
stages {
stage('Tests') {
parallel {
stage('x86') {
agent {
label 'x86'
}
steps {
// use the same configuration used for fetching the pipeline itself
checkout scm
}
}
stage('arm') {
agent {
label 'arm'
}
steps {
// use the checkout step - in this case for Git SCM
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[credentialsId: 'my-private-key-credential-id', url: 'http://git-server/user/repository.git']]])
}
}
stage('x64') {
agent {
label 'x64'
}
steps {
// use the shortened git step
git branch: 'master', credentialsId: 'my-private-key-credential-id', url: 'https://github.com/jenkinsci/jenkins.git'
}
}
}
}
}
}
您現在可以選擇在每個構建代理上定義不同的憑據,它們將在結帳程序中使用。另一種選擇是使用credentialsIdSCM 步驟具有的選項,在 Jenkins 中定義 SCM 提供程式所需的憑據(用戶名和密碼或 ssh 密鑰)并將它們傳遞給步驟 - 這樣您就不需要在代理人。有關更多資訊,
請參閱在 Jenkins 中使用憑據。
此外,所有傳遞給 SCM 步驟的引數(branch、url、credentialsId 等)都可以定義為 Job 引數 - 允許您更靈活、更輕松地執行不同的配置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/475328.html
