簡體   English   中英

如何訪問 jenkins 管道中 shell 腳本中的 groovy 變量?

[英]How to access a groovy variable in shell script in jenkins pipeline?

嘗試創建一個 jenkins 管道,該管道具有以下代碼以從用戶獲取輸入並在 shell 腳本中打印該輸入:

script{
        def user_input= input id: 'user_input', message: 'Choose a service which you want to deploy', ok: 'Confirm', parameters: [string(defaultValue: 'default', description: 'Entered value must be within range', name: 'selection', trim: true)]
        echo user_input //works fine
    
    sh '''
        #!/bin/bash
        set +x
        echo Step 2
        echo "${user_input}" //Printing blank space
        '''
     }

如果我像這樣使用 shell 它也可以正常工作:

sh "echo $user_input"

在 shell 腳本中對 groovy 變量使用雙引號: sh "echo $user_input"我認為另一個問題可能是您在腳本之外使用sh ,您在其中聲明了user_input變量。

暫無
暫無

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

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