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

时间:2019-06-18 10:03:17

标签: jenkins jenkins-pipeline jenkins-plugins jenkins-groovy jenkins-cli

我有一个主计算机(Unix)和一个从属计算机(Windows)。 我已经在主服务器和触发器请求上创建了一个多分支管道项目,所有过程都在从站中进行。我正在尝试发送从机上生成的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'
    }

文件应附加到电子邮件并发送。当前它显示错误:

  

错误:找不到工作区!

1 个答案:

答案 0 :(得分:1)

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