如何从声明管道中的archiveArtifact中排除文件?

时间:2018-05-08 12:54:06

标签: jenkins jenkins-pipeline

    stage('Publish') {
        steps {
                bat 'dotnet publish -c Release'
        }

        post {
            always {
                archiveArtifacts artifacts: """/bin/publish/**""", excludes: """/bin/publish/Tests/**""", """/bin/publish/coverage/**""", fingerprint: true
            }
        }
    }

为此,我收到错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 57: Arguments to "archiveArtifacts" must be explicitly named. @ line 57, column 21.
                       archiveArtifacts artifacts: """/bin/publish/**""", excludes: """/bin/publish/Tests/**""", """/bin/publish/coverage/**""", fingerprint: true
                       ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

1 个答案:

答案 0 :(得分:4)

archiveArtifacts的第三个参数未命名。即在你的电话中:

archiveArtifacts artifacts: """/bin/publish/**""", excludes: """/bin/publish/Tests/**""", """/bin/publish/coverage/**""", fingerprint: true

您的部分, """/bin/publish/coverage/**""",没有被命名。我猜你想让它成为exclude参数的一部分,在这种情况下你应该用逗号分隔第一个排除模式字符串中的两个排除模式,如下所示:

archiveArtifacts artifacts: """/bin/publish/**""", excludes: """/bin/publish/Tests/**, /bin/publish/coverage/**""", fingerprint: true

同样@Fidel指出,你不需要使用三重引用的字符串,所以你可以这样做:

archiveArtifacts artifacts: "/bin/publish/**", excludes: "/bin/publish/Tests/**, /bin/publish/coverage/**", fingerprint: true

或使用单引号:

archiveArtifacts artifacts: '/bin/publish/**', excludes: '/bin/publish/Tests/**, /bin/publish/coverage/**', fingerprint: true