【问题标题】:Jenkins Pipelines periodic build not sending email notification due to empty list of recipients由于收件人列表为空,Jenkins Pipelines 定期构建不发送电子邮件通知
【发布时间】:2020-04-16 19:03:15
【问题描述】:

我们使用每天定期运行的简单管道作业设置了夜间构建,但开发人员没有收到电子邮件通知。

我们使用emailextplugin 发送这些电子邮件,并使用Kubernetes agents 作为节点。

该作业由计时器启动,因为它是定期构建,使其运行以下管道配置(您可以忽略代理的容器定义,因为它不相关,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)触发作业时 - 收件人列表始终为空:

尝试向空的收件人列表发送电子邮件,被忽略。

可能是什么问题?

【问题讨论】:

    标签: jenkins jenkins-pipeline email-ext


    【解决方案1】:

    显然,所有接收者提供者都返回空列表。

    • requestor() 返回空列表,因为没有请求者
    • upstreamDevelopers() 返回空列表,因为没有 上游构建

    检查source code 找出为什么culprits()developers()brokenBuildSuspects()brokenTestsSuspects() 返回空列表。

    【讨论】:

      【解决方案2】:

      另一种方法是使用 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}"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-17
        • 1970-01-01
        相关资源
        最近更新 更多