问题:hudson.FilePath is missing error 当通过管道脚本生成诱惑报告时

我在管道中添加了新阶段:

stage('reports') {
    steps {
    script {
            allure([
                    includeProperties: false,
                    jdk: '',
                    properties: [],
                    reportBuildPolicy: 'ALWAYS',
                    results: [[path: 'target/allure-results']]
            ])
        }
    }
}

但是作业失败并出现错误:

hudson.remoting.ProxyException: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
    at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:260)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:262)
Caused: hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing

测试是在 Python 和生成的 xml 报告上编写的,但不是诱惑报告。

你能帮我解决这个错误吗?

解答

如我所见,您使用声明性管道语法。在这种情况下,您需要定义agent部分。来自官方文档:

在 Pipeline 的顶层定义agent none可确保不会不必要地分配 Executor。使用agent none还会强制每个stage部分包含其自己的agent部分。

所以,我认为你在管道的顶层使用agent none,这就是为什么你需要在你的阶段中添加agent部分。像这样的东西:

pipeline {
    agent none 
    stages {
        stage('reports') {
            agent { docker 'openjdk:8-jre' }
            steps {
                script {
                    allure([
                        includeProperties: false,
                        jdk: '',
                        properties: [],
                        reportBuildPolicy: 'ALWAYS',
                        results: [[path: 'target/allure-results']]
                    ])
                }
            }
        }
    }
}

对于脚本化管道您需要使用此语法(有关详细信息,请参阅 allure文档):

node {
// script body

allure([
         includeProperties: false,
         jdk: '',
         properties: [[key: 'allure.issues.tracker.pattern', value: 'http://tracker.company.com/%s']],
         reportBuildPolicy: 'ALWAYS',
         results: [[path: 'target/allure-results'], [path: 'other_target/allure-results']]
         ])
}
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐