最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jenkins?pipeline中獲取shell命令的標(biāo)準(zhǔn)輸出或者狀態(tài)的方法小結(jié)

 更新時(shí)間:2024年02月17日 10:18:45   作者:發(fā)哥隨手記  
這篇文章主要介紹了jenkins?pipeline中獲取shell命令的標(biāo)準(zhǔn)輸出或者狀態(tài),工作中需要獲取shell?命令的執(zhí)行狀態(tài),返回0或者非0,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
//獲取標(biāo)準(zhǔn)輸出
//第一種
result = sh returnStdout: true ,script: "<shell command>"
result = result.trim()
//第二種
result = sh(script: "<shell command>", returnStdout: true).trim()
//第三種
sh "<shell command> > commandResult"
result = readFile('commandResult').trim()
//獲取執(zhí)行狀態(tài)
//第一種
result = sh returnStatus: true ,script: "<shell command>"
result = result.trim()
//第二種
result = sh(script: "<shell command>", returnStatus: true).trim()
//第三種
sh '<shell command>; echo $? > status'
def r = readFile('status').trim()
//無(wú)需返回值,僅執(zhí)行shell命令
//最簡(jiǎn)單的方式
sh '<shell command>'

例如:
工作中需要獲取shell 命令的執(zhí)行狀態(tài),返回0或者非0
groovy語(yǔ)句寫法為:

def exitValue = sh(script: "grep -i 'xxx' /etc/myfolder", returnStatus: true)
// 如果grep命令執(zhí)行沒(méi)有報(bào)錯(cuò),正常情況下exitValue為0,報(bào)錯(cuò)則為非0
echo "return exitValue :${exitValue}"
if(exitValue != 0){
   //執(zhí)行操作
}

需要注意的是當(dāng)命令中存在重定向的時(shí)候,會(huì)出現(xiàn)返回狀態(tài)異常,因?yàn)槲覀円祷貭顟B(tài),刪除重定向(&>/dev/null)即可,比如:

def exitValue = sh(script: "grep -i 'xxx' /etc/myfolder &>/dev/null", returnStatus: true)
// xxx不存在,正常邏輯是返回非0,但是實(shí)際中返回的是0 。
// 可以理解為先執(zhí)行命令然后賦值操作,類似下面的動(dòng)作:(個(gè)人理解)
sh "ls -l > commandResult"
result = readFile('commandResult').trim()

groovy中存在另外一種解析shell腳本的方法,在jenkins pipeline中會(huì)使用會(huì)報(bào)異常,jenkins相關(guān)資料中也沒(méi)有看到此種用法,應(yīng)該是不支持

groovy.lang.MissingPropertyException: No such property: rhel for class: groovy.lang.Binding

寫法為:

def command = "git log"
def proc = command.execute()
proc.waitFor()
def status = proc.exitValue()

到此這篇關(guān)于jenkins pipeline中如何獲取shell命令的標(biāo)準(zhǔn)輸出或者狀態(tài)的文章就介紹到這了,更多相關(guān)jenkins pipeline獲取shell命令內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

咸宁市| 西城区| 宜黄县| 谢通门县| 普洱| 雷山县| 资兴市| 松原市| 迭部县| 武乡县| 邻水| 都兰县| 永泰县| 全州县| 娄底市| 贵南县| 寻甸| 泽普县| 垫江县| 东兴市| 自贡市| 彭泽县| 齐河县| 磐石市| 杭锦旗| 昭觉县| 石楼县| 临洮县| 蕉岭县| 进贤县| 甘肃省| 溧水县| 道孚县| 当涂县| 宜章县| 和硕县| 辽源市| 平江县| 清涧县| 葫芦岛市| 平度市|