Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins管道中的Shell cmds未执行_Shell_Jenkins_Groovy_Jenkins Pipeline - Fatal编程技术网

Jenkins管道中的Shell cmds未执行

Jenkins管道中的Shell cmds未执行,shell,jenkins,groovy,jenkins-pipeline,Shell,Jenkins,Groovy,Jenkins Pipeline,我想执行一个cURL命令,提取Json变量(使用jq)并将其保存在Jenkins管道中的变量中。在自由泳中,当我选择执行Shell并给出以下命令时,我将获得有效的成功输出和所有值。 , 非常感谢您的帮助。您可以尝试将整个过程放到一个shell脚本中。问题是您分配给的环境变量不存在于单个sh语句的末尾。我现在理解了这个问题,谢谢。我需要看看如何将整个过程放在一个shell脚本中&从管道调用它。感谢@KeepCalmAndCarryOn指出问题所在。我在管道中使用了一个shell脚本&它起作用了。

我想执行一个cURL命令,提取Json变量(使用jq)并将其保存在Jenkins管道中的变量中。在自由泳中,当我选择执行Shell并给出以下命令时,我将获得有效的成功输出和所有值。 ,


非常感谢您的帮助。

您可以尝试将整个过程放到一个shell脚本中。问题是您分配给的环境变量不存在于单个
sh
语句的末尾。我现在理解了这个问题,谢谢。我需要看看如何将整个过程放在一个shell脚本中&从管道调用它。感谢@KeepCalmAndCarryOn指出问题所在。我在管道中使用了一个shell脚本&它起作用了。
deployment_info=$(curl -H "Authorization: Basic a123=" "https://api.sample.com/v1") 

rev_num=$(jq -r .environment[0].revision[0].name <<< "${deployment_info}" ) 
env_name=$(jq -r .environment[0].name <<< "${deployment_info}" ) 
api_name=$(jq -r .name <<< "${deployment_info}" ) 
org_name=$(jq -r .organization <<< "${deployment_info}" )

declare -r num1=1
pre_rev=$(expr "$rev_num" - "$num1")

echo $rev_num
echo $api_name
echo $org_name
echo $env_name
echo $pre_rev
def deployment_info
def rev_num
def env_name
def org_name
def api_name
def pre_rev
def num1

node {


 stage('Integration Tests') {
  sh "deployment_info=\$(curl --header 'Authorization: Basic abc123=' 'https://api.sample.com/v1')"
  sh "rev_num=\$(jq -r .environment[0].revision[0].name <<< \"${deployment_info}\")"
  sh "env_name=\$(jq -r .environment[0].name <<< \"${deployment_info}\" ) "
  sh "api_name=\$(jq -r .name <<< \"${deployment_info}\" ) "
  sh "org_name=\$(jq -r .organization <<< \"${deployment_info}\" )"

  sh "declare -r num1=1"
  sh "pre_rev=\$(expr \"$rev_num\" - \"$num1\")"

  sh "echo $rev_num"
  sh "echo $api_name"
  sh "echo $org_name"
  sh "echo $env_name"
  sh "echo $pre_rev"

 }
}
[Pipeline] sh
[curlpip] Running shell script
++ jq -r '.environment[0].revision[0].name'
+ rev_num=null
[Pipeline] sh
[curlpip] Running shell script
++ jq -r '.environment[0].name'
+ env_name=null
[Pipeline] sh
[curlpip] Running shell script
++ jq -r .name
+ api_name=null
[Pipeline] sh
[curlpip] Running shell script
++ jq -r .organization
+ org_name=null
[Pipeline] sh
[curlpip] Running shell script
+ declare -r num1=1
[Pipeline] sh
[curlpip] Running shell script
++ expr null - null
expr: non-integer argument
+ pre_rev=
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE