dawn-liu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

先看一个例子,原理,根据命令返回的状态值来判断它的存在与否

pipeline {
    agent any    
    stages {
       stage("check file if exists"){    #执行此步的名称
         steps{
           script{
                 out=sh(script:"ls /tmp/uu.txt",returnStatus:true)
                 println "--------------"
                 println out
                 if(out == 0){
                    println "file is exist"   #println 类似于java语法:打印并回车
                 }else if(out == 2){
                    println "file is not exist"
                 }else{
                   error("command is error,please check")  #命令有误一般状态码为127
                 }
            }
         }
        }  
    }
}
sh(script:"ls /tmp/uu.txt",returnStatus:true)
sh执行一个shell,脚本内容:ls /tmp/uu.txt returnStatus:true 返回结果的状态吗,还有一个常用的参数 returnStdout:true 它返回的是结果的输出

 

posted on 2019-09-03 18:19  dawn-liu  阅读(5039)  评论(0编辑  收藏  举报