嵌入脚本-01

原 XMind 内的文本附件快照。仅展示,不执行;已识别口令会被遮蔽,其余路径、账号、凭据引用和环境假设仍需人工审查。

原资源:resources/524148815dafafec6390dc4fc7d44c1ad932c82467245e4de61f5370264e2fa9.txt

 
currentBuild.displayName = "devops"
currentBuild.description = "branch: master"
//choice node
choiceBuildNode = "build"
 
pipeline {
    agent { 
        node { 
            label "${choiceBuildNode}"
            customWorkspace "/home/jenkins/workspace/workspace/newws" 
        } 
    }
 
    stages {
        stage('Build') {
            steps {
                echo 'Hello World'
                println("devops")
                script{
                    // groovy code
                    name = "jenkins"
                    if (name == "jenkins"){
                        println("true")
                    }
                    
                    sh 'ls -l '
                    sh '''
                        echo ${name}
                        ls -l 
                        ls 
                    '''
                }
            }
        }
        stage('Test') {
            steps {
                echo 'Hello World'
                echo "build_id: ${BUILD_ID}"
                echo "build_url:${BUILD_URL}"
            }
        }
    }
 
    post {
      always {
        // One or more steps need to be included within each condition's block.
        sh "ls -l "
        script {
            println("always")
        }
      }
      success {
        sh " ls -s"
        script{
            println("success")
        }
      }
    }
}
 

来源主题: