![](/img/trans.png)
[英]How to use shell script variable as groovy variable in Jenkins pipeline script
[英]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.