jenkins pipeline: multiline shell commands with pipe

☆樱花仙子☆ 提交于 2019-12-04 22:40:12

I tried entering all these commands in the jenkins snippet generator for pipeline and it gave the following output:

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
'''

Notice the escaped single quotes in the commands jq -r \'.public_url\' and jq -r \'.code\'. Using the code this way solved the problem

UPDATE: : After a while even that started to give problems. There were certain commands executing prior to these commands. One of them was grunt serve and the other was ./ngrok http 9000. I added some delay after each of these commands and it solved the problem for now.

I split the commands with &&

node {
  FOO = world
  stage('Preparation') { // for display purposes
      sh "ls -a && pwd && echo ${FOO}"
  }
}

The example outputs: - ls -a (the files in your workspace - pwd (location workspace) - echo world

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!