簡體   English   中英

將函數參數傳遞給字符串 groovy 文件 Jenkins 管道

[英]Pass function argument to string groovy file Jenkins pipeline

我有一個將數據上傳到 S3 的 Jenkins 管道。 S3 目的地應該不同,具體取決於分支是否為主分支。 到目前為止,我已經在build.groovy文件中嘗試過這個:

import lib.Constants
def s3Deploy() {
    script {
        if(env.BRANCH_NAME == 'master') {
            s3Deploy_func('codebase')
        }
        else {
            s3Deploy_func('new_codebase')
        }
    }
}

def s3Deploy_func(String s3_folder) {
    sh '''
    aws s3 cp "$WORKSPACE/" s3://${BUCKET_NAME}/$s3_folder --profile ${PROFILE} --recursive
    '''
}

return this

變量 Workspace、bucket_name 和 profile 被成功覆蓋。 但是,s3_folder 始終為空。 我也嘗試過${s3_folder} ,但還是一樣。 我怎么能解決這個問題? 謝謝

我認為它應該使用雙引號"""而不是'''${s3_folder}而不是{s3_folder}

所以修復應該是

sh """
aws s3 cp "$WORKSPACE/" s3://${BUCKET_NAME}/${s3_folder} --profile ${PROFILE} --recursive
"""

暫無
暫無

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

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