Curl(bash)命令在Jenkinsfile groovy脚本中不起作用 [英] Curl (bash) command not working in Jenkinsfile groovy script

查看:376
本文介绍了Curl(bash)命令在Jenkinsfile groovy脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Jenkinsfile Groovy脚本中,我有以下代码;

In my Jenkinsfile Groovy script, I have the following code;

stage('Test the 500 log URLs') {
      steps {
        script {
          echo 'Testing the URLs from the 500 error access log...'
                sh '''#!/bin/bash
                    while IFS= read -r line; do
                      URL=`echo $line | awk '{print $2}' | sed 's/http:/https:/' `
                      RESULT=`curl -LI $URL -o /dev/null -w "%{http_code}\n" -s | tr -d '[:space:]' `
                      if [[ $RESULT != "200" ]]
                        then
                          echo "$RESULT $URL"   
                      fi
                    done < tests/Smoke/logs_testing/500errors.txt
                  '''
        }
      }
    }

文件的第一部分可以正常工作,包括命令;

The first parts of the file work correctly, including the command;

URL=`echo $line | awk '{print $2}' | sed 's/http:/https:/' `

但是,下面一行;

RESULT=`curl -LI $URL -o /dev/null -w "%{http_code}\n" -s | tr -d '[:space:]' `

当我运行Jenkins版本时失败.

fails when I run the Jenkins build.

产生以下错误;

line 4: curl: command not found

我看不到上一行为什么运行正常,但是这一行失败了.

I can't see why the previous line ran ok, but this line is failing.

我明显缺少什么吗?

任何帮助将不胜感激.

谢谢

推荐答案

curl可能未安装在/usr/bin/之类的通用位置.我建议您尝试通过其完整路径运行curl.

It is possible that curl was not installed in a common location like /usr/bin/. I'd suggest you try to run curl via its full path.

$ which curl
/usr/somelocation/curl # <- just an example

然后在您的脚本中:

RESULT=`/usr/somelocation/curl -LI $URL...`

另一种选择是编辑/etc/profile并将其附加到PATH所在的任何位置.

Another option is to edit your /etc/profile and append to PATH wherever curl is located.

export PATH=$PATH:/usr/somelocation/

这篇关于Curl(bash)命令在Jenkinsfile groovy脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆