一、JenkinsFile 语法参数 env_tools 环境工具变量的定义设置位置: “Manage Jenkins”-> “Tools” stage('env tools') { node('test'){ //定义maven java环境 def mvnHome = tool 'MAVEN_HOME_CentOS' //引用环境变量,配置PATH变量 env.PATH = "${mvnHome}/bin:${env.PATH}" //调用 mvn 工具 sh "mvn --version" } } node{ stage('Example') { if (env.BRANCH_NAME == 'master') { echo 'I only execute on the master branch' } else { echo 'I execute else branch' } try { echo "This is in the try block." sh 'exit 1' }catch (exc) { echo "Something failed, I'm in the catch block." }finally { echo "Finally, I'm in the finally block." } } }