无法在 Jenkins 中使用 emailext 从从机和电子邮件附加文件

Not able to attach file from Slave machine and email using emailext in Jenkins

我有一台主机 (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'
    }

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

Error: No workspace found!

根据我的测试,似乎 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
        }
    }
}