jenkins pipeline 常用句式

Jenkinsfile
邮件报警需要安装emailext插件,这个插件可以把jenkins发布的日志加到邮件中,以及使用模板
脚本式 jenkins pipeline 发送邮件

//=================自定义信息===============
//harbor 仓库名称, 例如mobile,computer,testmonitor等等
def harbor_project = "mobile"
//docker构建版本tag
def tag = "latest"
//git 地址
def git_addr= "git@github.com:api/mobile-go.git"
//=================定义公用信息===============
//harbor地址
def harborUrl = "harbor.test.com"
//harbor测试
def harborAuth = "495d3b1a-a616-44d3-ae91-4b6e004076bd"
//gitlab的凭证
def git_auth = "330de1e8-1525-45e5-971e-da440ad5b810"
//获取当前选择的项目名称
def selectedProjects = "${project_name}".split(',')

node {
    try {


       stage('拉取代码') { // for display purposes
          // Get some code from a GitHub repository
         checkout([$class: 'GitSCM', branches: [[name: "${git_version}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_addr}"]]])
          // Get the Maven tool.
          // ** NOTE: This 'M3' Maven tool must be configured
          // **       in the global configuration.
       }

        stage('代码编译') {
            for(int i=0;i<selectedProjects.size();i++){
                //取出每个项目的名称
                def currentProjectName = selectedProjects[i];
                    echo "${currentProjectName}"
                    echo "做点什么,已省略。。。"
            }
        }
        currentBuild.result = 'SUCCESS'
    }

    catch(e) {
        currentBuild.result = 'FAILURE'
    }

    finally {
        emailext attachLog: true, body: '$DEFAULT_CONTENT', subject: "[JENKINS]V3 ${selectedProjects}发布${currentBuild.result}", to: 'xxx@test.com;'
    }
}
上一篇:Jenkins教程(六)脚本与方法执行效果不合预期,如何及时中止pipeline


下一篇:jenkins pipeline