如何将命令输出保存到 Jenkinsfile Shell 步骤中的变量?
How to save a command output to a variable in a Jenkinsfile Shell step?
我有以下代码:
...
stage('Some stage') {
sh """
#!/bin/bash
CHECK=$(curl -sI https://somegithuburl.com)
echo $CHECK
"""
}
...
当 Jenkins 作业执行时 returns:
+ CHECK=
您知道如何像在 Shell 脚本中那样将输出保存在变量中吗?
尝试:
export CHECK=`curl -sI https://somegithuburl.com`;
echo $CHECK
拉取输出并保存为变量的正确方法:
export CHECK="$(curl -s https://somegithuburl.com)"
那么你可以使用$CHECK
作为变量
我有以下代码:
...
stage('Some stage') {
sh """
#!/bin/bash
CHECK=$(curl -sI https://somegithuburl.com)
echo $CHECK
"""
}
...
当 Jenkins 作业执行时 returns:
+ CHECK=
您知道如何像在 Shell 脚本中那样将输出保存在变量中吗?
尝试:
export CHECK=`curl -sI https://somegithuburl.com`;
echo $CHECK
拉取输出并保存为变量的正确方法:
export CHECK="$(curl -s https://somegithuburl.com)"
那么你可以使用$CHECK
作为变量