首页 > 解决方案 > 无法在 Jenkins 中使用 emailext 从 Slave 机器和电子邮件附加文件

问题描述

我有一台主机(Unix)和一台从机(Windows)。我已经在 Master 和 Trigger 请求上创建了一个多分支管道项目,所有流程都在 Slave 中进行。我正在尝试发送在从机上生成的 HTML 报告,但得到异常:

ERROR: Error: No workspace found!  
Sending email to: abhishek.gaur1@pb.com  
[Pipeline] }  
[Pipeline] // stage  
[Pipeline] End of Pipeline  
Finished: SUCCESS  

我在 Jenkinsfile 中使用以下代码:

success {
    emailext attachmentsPattern: '**/overview-features.html',
    body: '${SCRIPT, template="groovy-html.template"}',
    mimeType: 'text/html',
    subject: 'Success Pipeline: ${currentBuild.fullDisplayName}',
    to: 'abhishek.gaur1@pb.com'
    }

该文件应附在电子邮件中并发送。目前它显示错误:

错误:找不到工作区!

标签: jenkinsjenkins-pipelinejenkins-pluginsjenkins-groovyjenkins-cli

解决方案


从我的测试来看,这种情况似乎agent none在配置中存在问题,即工作空间未在主服务器上分配。

agent none允许在每个阶段设置代理,但该post()块不允许设置代理,它将在没有工作区的情况下在agent none我收集的情况下在主服务器上运行。

因此,在这种情况下,声明性管道的唯一解决方案是在带有标签Developer30的代理上运行整个构建,如果您的示例完整,则应该没问题。

pipeline { 

    agent { 
        label 'Developer30' 
    }

    tools { 
        maven 'MAVEN_HOME' 
    } 

    stages { 
        stage ('Compile Stage') {              
            steps { 
                bat 'mvn clean' 
            } 
        } 
    }

    post { 
        success { 
            // emailext stuff
        }
    }
}

推荐阅读