Trying to use Publishers as Builders in Job DSL

176 views
Skip to first unread message

Nicholas Anderson

unread,
Jan 9, 2018, 5:38:04 PM1/9/18
to job-dsl-plugin
I'm using the Any Build Step plugin with the Conditional BuildStep plugin to add an archive artifacts publisher as a builder. It works fine in the UI and generates this XML in the job's config.xml.

    <org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder plugin="conditiona...@1.3.6">
     
<condition class="org.jenkins_ci.plugins.run_condition.core.AlwaysRun" plugin="run-condition@1.0"/>
     
<buildStep class="hudson.tasks.ArtifactArchiver">
       
<artifacts>*.css</artifacts>
       
<allowEmptyArchive>true</allowEmptyArchive>
       
<onlyIfSuccessful>false</onlyIfSuccessful>
       
<fingerprint>true</fingerprint>
       
<defaultExcludes>true</defaultExcludes>
       
<caseSensitive>true</caseSensitive>
     
</buildStep>
     
<runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail" plugin="run-condition@1.0"/>
   
</org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder>

I've tried a few variations of Job DSL code, but there's an example of what I've done below. This code errors, replacing steps with publishers puts the archive in a publisher instead of in the build step.

steps {  
 
// Create an artifact of the files produced in the build.
  conditionalSteps
{
    condition
{
      alwaysRun
()
   
}
    runner
('Fail')
    steps
{
      archiveArtifacts
{
        pattern
('*.css')
        allowEmpty
()
     
}
   
}
 
}
}

I'm wondering if the Job DSL supports using publishers as builders? Maybe it only supports using builders as publishers. The documentation for Any Build Step here https://jenkinsci.github.io/job-dsl-plugin/#plugin/any-buildstep seems to suggest that steps only has a conditionalAction context, which only has a FlexiblePublisher context.

If anyone could point me in the right direction for how to use a publisher as a builder in the Job DSL, it would be greatly appreciated!

  

Victor Martinez

unread,
Jan 10, 2018, 5:10:21 AM1/10/18
to job-dsl-plugin
Hey,

https://github.com/jenkinsci/job-dsl-plugin/wiki/Automatically-Generated-DSL doesn't show any generated ones in the https://jenkinsci.github.io/job-dsl-plugin/# therefore you need to look at your api-viewer:

- <YOUR_JENKINS_URL>/plugin/job-dsl/api-viewer/index.html#path/javaposse.jobdsl.dsl.helpers.step.StepContext.conditionalBuilder-conditionalbuilders-archiveArtifacts

In your case you were missing the 'conditionalBuilder'

Something like the below snippet should work (although I have not tested it out)

job('example-1') {
    steps
{
        conditionalSteps
{
            condition
{
               
//
           
}
           
conditionalBuilder {

Nicholas Anderson

unread,
Jan 10, 2018, 1:22:05 PM1/10/18
to job-dsl-plugin
Thank you! I didn't realize that the api-viewer would have extra things compared to the online documentation. I was able to figure out how to get it to run from the documentation. It was a bit weird, it's not set up the same as other conditional steps . So just for posterity, this is what worked:

steps {
 
// Create an artifact of the files produced in the build.

  conditionalBuilder
{
    runCondition
{
      alwaysRun
()
   
}
    runner
{
      fail
()
   
}
    conditionalbuilders
{
      archiveArtifacts
{
        artifacts
("*.css,*.map")
        allowEmptyArchive
(true)
        fingerprint
(true)
        caseSensitive
(true)
     
}
   
}
 
}
}
Reply all
Reply to author
Forward
0 new messages