- 发送邮件
https://blog.csdn.net/qq_30141993/article/details/81031151
import jenkins.model.*
@NonCPS
def getJobNames() {
Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob)*.fullName
}
pipeline {
agent any
stages {
stage('Test Stage') {
steps {
sh '''
pwd
'''
}
}
stage('getJobNames') {
steps {
script {
def jobNames = getJobNames()
def matchjobs = jobNames.findAll{ name -> name =~ /(test)\w*/ }
// println matchjobs
matchjobs.each {
try {
println(it)
res = jenkins.model.Jenkins.instance.getItem(it).lastBuild.getResult()
println res
} catch (NullPointerException e1) {
e1.printStackTrace();
}
}
}
}
}
}//stages
post {
always {
echo 'This will always run'
script {
emailext (subject:'${ENV, var ="JOB_NAME"}',
body:'${FILE ,path="email.html"}',
to:'sgamize@sina.com',)
}
}
success {
echo 'This will run only if successful'
}
failure {
echo 'This will run only if failed'
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}