当前位置:   article > 正文

jenkins pipeline通过chage-id获取远程change分支名导致shell命令一直失败_jenkins pipline changes

jenkins pipline changes

出现的问题:

出现问题的代码如下: 

  1. def cherry_pick() {
  2. String cherryPickCommitId = CHERRY_PICK_COMMITID
  3. String cherryPickBranch = CHERRY_PICK_BRANCH
  4. echo "cherryPickBranch = ${cherryPickBranch}"
  5. echo "cherryPickCommitId = ${cherryPickCommitId}"
  6. String[] str;
  7. str = cherryPickCommitId.split(' ');
  8. echo "cherryPickCommitId : "
  9. for( String values : str ) {
  10. println(values)
  11. int patch_sets_number = sh( returnStdout: true, script: "ssh -p 29418 user@git.***.com gerrit query --format=JSON --patch-sets change:${values} | sed -n '1p' | jq '.patchSets' | grep number | wc -l")
  12. echo "patch_sets_number=${patch_sets_number}"
  13. int patch_sets_latest = patch_sets_number - 1
  14. echo "patch_sets_latest=${patch_sets_latest}"
  15. def refs_change = sh( returnStdout: true, script: "ssh -p 29418 user@git.***.com gerrit query --format=JSON --patch-sets change:${values} | sed -n '1p' | jq '.patchSets[$patch_sets_latest].ref' | sed 's/\"//g'")
  16. echo "patch_sets_latest = ${patch_sets_latest} refs_change = ${refs_change}"
  17. sh "git fetch idb ${refs_change}:${values}"
  18. }
  19. }

解决:将获取jsonl里的分支名后删除换行符就可以了 

def refs_change = sh(  returnStdout: true, script: "ssh -p 29418 aiot-robot@git.xiaomi.com  gerrit query --format=JSON --patch-sets change:${values} | sed -n '1p' | jq '.patchSets[$patch_sets_latest].ref' | xargs echo -n | sed 's/\"//g'")

删除换行符的操作,最简单的是:

echo  "55555" | xargs echo -n 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/621458
推荐阅读
相关标签
  

闽ICP备14008679号