簡體   English   中英

'sh:sh:找不到命令'在多分支管道中使用withCredentials塊時

[英]'sh: sh: command not found' When using withCredentials block in multibranch pipeline

我正在建立一個Jenkins多分支管道,以使用Fastlane為Crashlytics構建iOS應用。 現在,Crashlytics的API密鑰和構建秘訣以明文形式存儲在我的Fastfile中,因此我想將它們移至Jenkins憑證,以便任何訪問我的GitHub存儲庫的人都無法獲得信息。

我按照此處詳細說明創建了憑證並從Jenkinsfile訪問它們。 我將它們創建為“秘密文本”類型的憑據。 這是他們在Jenkins中的樣子(沒有足夠的代表來發布圖像,因此有一些鏈接): api令牌憑證 建立秘密憑證

這是我在Jenkinsfile中訪問這些憑據的方式:

pipeline {
    agent any
    stages {
        ...
        stage('Deploy Patient App') {
            steps {
                withCredentials([
                    string(credentialsId: 'crashlytics_api', variable: 'api_token'),
                    string(credentialsId: 'crashlytics_build', variable: 'build_secret')
                ]) {
                    sh '''
                        set +x
                        bundle exec fastlane deploy app:\'Therapy\' api_token:$api_token build_secret:$build_secret
                    '''
                }
            }
        }
        ...
    }
}

現在,當我在詹金斯中運行管道時,得到以下輸出:

[Pipeline] stage
[Pipeline] { (Deploy Patient App)
[Pipeline] withCredentials
Masking supported pattern matches of $api_token or $build_secret
[Pipeline] {
[Pipeline] sh
sh: sh: command not found

我的Jenkinsfile中我在做什么錯? 還是其他地方存在問題?

我也是新來的,但我想我可以幫忙...

我做了一些研究並發現了這個問題: https : //github.com/jenkinsci/aws-credentials-plugin/issues/22#issuecomment-317203165

盡管這是另一個插件,但我注意到它們的相似之處在於它們也使用了聲明性管道,並且它們不需要script {}塊。

用您的代碼替換Github注釋中的差異如下:

stage('Deploy Patient App') {
    steps {
        withCredentials([
            string(credentialsId: 'crashlytics_api', variable: 'api_token'),
            string(credentialsId: 'crashlytics_build', variable: 'build_secret')
        ]) {
            sh 'bundle exec fastlane deploy app:\'Therapy\' api_token:$api_token build_secret:$build_secret'
        }
    }
}

另一個建議是使用雙引號" " ,否則它們將收到script.sh: Bad substitution錯誤。

PS:抱歉,我自己無法測試此代碼,但在Github上確實獲得了很多好評。 希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM