我想创建一个詹金斯管道,我需要执行多个shell命令并在下一个命令左右使用一个命令的结果。我发现在一对三个单引号'''
中包装命令可以完成相同的操作。但是,在使用pipe将一个命令的输出提供给另一个命令时,我遇到了一些问题。例如詹金斯管道:与管道多行shell命令
stage('Test') {
sh '''
echo "Executing Tests"
URL=`curl -s "http://localhost:4040/api/tunnels/command_line" | jq -r '.public_url'`
echo $URL
RESULT=`curl -sPOST "https://api.ghostinspector.com/v1/suites/[redacted]/execute/?apiKey=[redacted]&startUrl=$URL" | jq -r '.code'`
echo $RESULT
'''
}
带管的命令无法正常工作。这里是詹金斯控制台输出:
+ echo Executing Tests
Executing Tests
+ curl -s http://localhost:4040/api/tunnels/command_line
+ jq -r .public_url
+ URL=null
+ echo null
null
+ curl -sPOST https://api.ghostinspector.com/v1/suites/[redacted]/execute/?apiKey=[redacted]&startUrl=null
我知道但是它可能会帮助其他人,只需在命令后面添加一个;按照您的示例, stage('Test'){ sh''' echo“Executing Tests”; UR L ='curl -s“http:// localhost:4040/api/tunnels/command_line”| jq -r'.public_url''; echo $ URL; RESULT ='curl -sPOST“https://api.ghostinspector.com/v1/suites/[redacted]/execute/?apiKey=[redacted]&startUrl=$URL”| jq -r'.code'; echo $ RESULT; ''' } 我在詹金斯做了很多,这从来没有失败过。虽然我只是做了一个衬里(冷凝器在这里)没有多条漂亮的线:P – Nelson