jenkins流水线pipeline脚本实例

前端之家收集整理的这篇文章主要介绍了jenkins流水线pipeline脚本实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

发送邮件

import hudson.model.*;
 
println env.JOB_NAME
println env.BUILD_NUMBER
 
pipeline{
    
    agent any
    stages{
        stage("send mail test") {
            steps{
                script {
                    mail to: '1399811201@qq.com',
                    subject: "Running Pipeline: ${currentBuild.fullDisplayName}",1)">
                    body: "Something is wrong with ${env.BUILD_URL}"
                }
            }
        }
    }
}

发送邮件svn日志内容

pipeline {
    agent any
    stages {
        stage('代码') {
            steps {
                checkout("svn代码")
            }
        }
        stage(输出日志) {
            steps {
                script{
                    //调用方法得到日志并输出
                    def changeString = getChangeString()
                    echo $changeString
                }
            }
        }
        stage(发送邮件) {
            steps{
                script {
                    
                    mail to: qq@qq.com,subject: ${JOB_NAME}  (${BUILD_NUMBER})-提交SVN日志信息SVN版本变更信息:\n$changeString\n构建日志: $BUILD_URL/console
                }
            }
        }
    }
}

@NonCPS
def getChangeString() {
    MAX_MSG_LEN = 100
    def changeString = ""
    Gathering SCM changes
    def changeLogSets = currentBuild.changeSets
    for (int i = 0; i < changeLogSets.size(); i++) {
        def entries = changeLogSets[i].items
        int j = 0; j < entries.length; j++) {
            def entry = entries[j]
            truncated_msg = entry.msg.take(MAX_MSG_LEN)
            changeString += ${truncated_msg} -- ${entry.author}\n
        }
    }

    if (!changeString) {
        changeString = ${currentBuild.fullDisplayName}:当前构建版本没有新的变更信息!
    }
    return changeString
}

 

原文链接:/jenkins/992133.html

猜你在找的Jenkins相关文章