如何在跑步后将Jenkins工作区的内容作为电子邮件附件发送

pn9klfpd  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(182)

Jenkins构建工作区的内容如何在测试运行后作为电子邮件附件发送?下面是我的声明性管道代码片段。我可以在管道运行后看到工作区中的文件夹和文件,但除了构建日志外,它没有附加:-

stage('Send Test Report') {
            steps {
                script {

                    def testEmailGroup = "saba@abc.com"
                    // Test teams email
                    emailext(
                              subject: "STARTED: jOB '${env.JOB_NAME} [${env.BUILD_NUMBER}]' RESULT: ${currentBuild.currentResult}",
                              attachLog: true, attachmentsPattern: "**/${WORKSPACE}/*.zip",compressLog: true,
                              body: "Check console output at   ${env.BUILD_URL}" ,

                            to: testEmailGroup)
                }
            }

        }
cnh2zyt3

cnh2zyt31#

您首先需要将工作区内容拖放到一个文件中,下面是一个类似于Jenkins的片段:

stages {
        stage('CreateAndSendReport') {
            steps {
                sh 'echo "Contents" > contents.txt'
            }
        }
    }
    post {
        always {
            archiveArtifacts artifacts: 'contents.txt', onlyIfSuccessful: true

            emailext attachLog: true, attachmentsPattern: 'contents.txt',
                body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n Link: ${env.BUILD_URL}",
                recipientProviders: [developers(), requestor()],
                subject: "Jenkins Build Report  ${currentBuild.currentResult}: Job ${env.JOB_NAME}"

        }
    }

相关问题