jenkins - 由于收件人列表为空,Jenkins Pipelines 定期构建不发送电子邮件通知
问题描述
我们使用每天定期运行的简单管道作业设置了夜间构建,但开发人员没有收到电子邮件通知。
我们使用emailext
插件将这些电子邮件和Kubernetes 代理作为节点发送。
该作业由计时器启动,因为它是定期构建,使其运行以下管道配置(您可以忽略代理的容器定义,因为它不相关,IMO):
pipeline {
agent {
kubernetes {
yaml """
metadata:
labels:
some-label: some-label-value
spec:
containers:
- name: agent
image: python:3.7
command:
- cat
tty: true
"""
}
}
options {
timestamps()
}
stages {
stage('SCM') {
steps {
checkout(
changelog: false,
poll: false,
scm: [$class : 'GitSCM',
userRemoteConfigs : [[credentialsId: 'Git SSH Key', url: 'git@bitbucket.org:company/repository.git']]],
branches : [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions : [[$class : 'CloneOption',
depth : 1,
noTags : false,
reference: '',
shallow : true],
[$class: 'PruneStaleBranch'],
[$class: 'GitLFSPull'],
[$class : 'SubmoduleOption',
disableSubmodules : false,
parentCredentials : true,
recursiveSubmodules: true,
reference : '',
trackingSubmodules : false]],
submoduleCfg : []
)
}
}
stage('Build') {
steps {
container('agent') {
echo '-> install tox'
sh 'pip install tox'
sh 'python --version'
sh 'pip --version'
}
}
}
stage('Test') {
steps {
container('agent') {
sh 'tox -c ./tox.ini'
}
post {
always {
echo '-> collecting artifacts'
archiveArtifacts allowEmptyArchive: true, artifacts: '*.txt'
echo '-> collecting test results'
junit allowEmptyResults: true, testResults: 'output/pytest.xml'
}
}
}
}
}
post {
changed {
emailext(
subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT',
recipientProviders: [culprits(),
developers(),
requestor(),
brokenBuildSuspects(),
brokenTestsSuspects(),
upstreamDevelopers()]
)
}
}
}
当手动启动作业(启动开发人员收到相关电子邮件)时,上述内容确实有效,但是,当从定期构建(cron)触发作业时 - 收件人列表始终为空:
尝试向空的收件人列表发送电子邮件,被忽略。
可能是什么问题?
解决方案
另一种方法是使用 git 获取提交者:
// Get all commits from the latest merge in an array
def gitCommits = sh(returnStdout: true, script: 'git log --merges -1 --format=%p').trim().split(' ')
// Get committer emails:
def emails = ""
gitCommits.each {
emails = emails + sh(returnStdout: true, script: 'git --no-pager show -s --format=%ae ${it}').trim() + ","
}
echo "${emails}"
推荐阅读
- javascript - Clicking on next button it saves form.But once I come back to previous page and again click on same next button it shows validation error message
- javascript - 未找到 React 模块 - 如何在反应中导入模块
- html - 在 Django 视图和模板中执行一些算术后,我得到了错误的值
- python - 为什么在 __exit__ 函数中更改引用不起作用?
- laravel - Laravel 返回注册 ID
- ios - 不要在选项卡开关的导航中重新加载顶部视图中的内容
- c - C API 允许自动和分配的存储
- loops - Python:While循环索引超出范围
- node.js - multer保存文件后修改req.body
- javascript - 使用给定模式验证日期输入 - JS / React