Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70289

Job DSL Can not generate ParameterizedRemoteTrigger parameters correctly

      I am trying to call a remote Jenkins Job with Parameters and caller Job is generated by Job DSL.

      I used the following Job DSL snippet as it is defined in the Documentation:
      https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.remoteTrigger

      Note: My local Jenkins Documentation is also same as the one in this general one

      steps {
          remoteTrigger(some-remote-vm, some-job-name) {
              parameter('artifactId', 'example-artifact')
              parameter('classifier', 'win64')
              parameter('extension', 'exe')
              parameter('version', '$releaseVersion')
              blockBuildUntilComplete()
              }
      } 

      As a result in config.xml I get:

      <builders>
          <org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration>
      ...
          <parameters>
              artifactId=example-artifact classifier=win64 extension=exe version=$releaseVersion
          </parameters>
          <parameterList>
              <string>artifactId=example-artifact</string>
              <string>classifier=win64</string>
              <string>extension=exe</string>
              <string>version=$releaseVersion</string>
          </parameterList>
      ...
      <builders> 

      However this was not visualized in the configuration GUI at all and Job execution has failed because of missing parameters.

      Then I tried to configure the Job with GUI by using map parameters. After Manuel configuration I get following XML part in config.xml:

      <builders>
        <org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration plugin="Parameterized-Remote-Trigger@3.1.6.3">
          <remoteJenkinsName>some-remote-vm</remoteJenkinsName>
          <parameters2 class="org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameters">
            <parameters>
              <org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
                <name>artifactId</name>
                <value>example-artifact</value>
              </org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
              <org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
                <name>classifier</name>
                <value>win64</value>
              </org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
              <org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
                <name>extension</name>
                <value>exe</value>
              </org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
              <org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
                <name>version</name>
                <value>$releaseVersion</value>
              </org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter>
            </parameters>
          </parameters2>
      ...
      <builders> 

      As a workaround when I manually generate this "parameters2" Object in the DSL by using custom XML generation then it works, but it is inconsistent with Documentation and inconvenient to reverse engineer it from XML:

      configure { projectNode ->
          def buildersNode = projectNode / builders    buildersNode.'org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration'.each { pluginNode ->
              pluginNode / blockBuildUntilComplete('true')
              pluginNode / pollInterval('30')
              pluginNode / parameters2(class: 'org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameters') {
                  parameters {
                      'org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter' {
                          name 'artifactId'
                          value 'example-artifact'
                      }
                      'org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter' {
                          name 'classifier'
                          value 'win64'
                      }
                      'org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter' {
                          name 'extension'
                          value 'exe'
                      }
                      'org.jenkinsci.plugins.ParameterizedRemoteTrigger.parameters2.MapParameter' {
                          name 'version'
                          value '$releaseVersion'
                      }
                  }
              } // parameters2
          }// for each node
      }// configure 

      Can you fix this so it can be generated by Job DSL as described on documentation without reverse engineering?

       

          [JENKINS-70289] Job DSL Can not generate ParameterizedRemoteTrigger parameters correctly

          Mehmet Can added a comment -

          Used Versions:

          Jenkins: 2.375.1 OS: Linux - 3.10.0-1160.76.1.el7.x86_64

          Parameterized-Remote-Trigger:3.1.6.3

          job-dsl:1.81

          Mehmet Can added a comment - Used Versions: Jenkins: 2.375.1 OS: Linux - 3.10.0-1160.76.1.el7.x86_64 Parameterized-Remote-Trigger:3.1.6.3 job-dsl:1.81

          Pavel added a comment - - edited

          I can confirm this issue with these versions:

          Jenkins 2.401.2; OS: Linux x64; Parameterized-Remote-Trigger: 3.1.6.3

          Job DSL: 1.84

           

          JobDSL part is broken.

          Pavel added a comment - - edited I can confirm this issue with these versions: Jenkins 2.401.2; OS: Linux x64; Parameterized-Remote-Trigger: 3.1.6.3 Job DSL: 1.84   JobDSL part is broken.

          IMHO: you should stop using hardcoded impl remoteTrigger, and instead use Job DSL dynamic support for this plugin : remoteBuildConfiguration , it works with pre 3.1.6 and post 3.1.6 versions.
          only difference 3.1.6+ added parameters2 support

          Denis Shvedchenko added a comment - IMHO: you should stop using hardcoded impl remoteTrigger, and instead use Job DSL dynamic support for this plugin : remoteBuildConfiguration , it works with pre 3.1.6 and post 3.1.6 versions. only difference 3.1.6+ added parameters2 support

          Pavel added a comment -

          dshvedchenko can you provide an example, please? Is there any documentation on it?

           

          Pavel added a comment - dshvedchenko can you provide an example, please? Is there any documentation on it?  

          Denis Shvedchenko added a comment - - edited

          as for documentation, any job that has JobDSL step has left side link to API docs Job DSL API Reference

          step = [
          	//credentialsId: "username-passowrd-pair-a",
          	parameters : [ ABC: '1234', CDE: 'second value', NMK: "absolute" ],
              jobName: "UTILS/provider_old",
            	remoteJenkins: "etl-test",
              token: "test-remote-job",
              //disabled: true,
              abortTriggeredJob: true,
            	enhancedLogging: true,
              maxConn: 4
            ]
          
          
          job('example-2') {
              steps {
                remoteBuildConfiguration {
                  remoteJenkinsName(step.remoteJenkins)
                  job(step.jobName)        
                  blockBuildUntilComplete(step.blockBuildUntilComplete?:false)
                  if (step.pollInterval) pollInterval(step.pollInterval)
                  shouldNotFailBuild(step.shouldNotFailBuild?:false)
                  preventRemoteBuildQueue(step.preventRemoteBuildQueue?:false)
                  if (step.token) token(step.token)
                  
                  if (step.disabled) disabled(step.disabled?:false)
                  if (step.maxConn) maxConn(step.maxConn?:1)
                  if (step.abortTriggeredJob) abortTriggeredJob(step.abortTriggeredJob?:false)
                  if (step.enhancedLogging) enhancedLogging(step.enhancedLogging?:false)
          
                  if (step.credentialsId) auth2 {
                    CredentialsAuth {
                      credentials(step.credentialsId)
                    }
                  }
          
                  if (step.parameters && step.parameters.size() > 0) {        
                    try {
                      parameters2 {
                          MapParameters {
                            parameters{
                              step.parameters.each { entry ->
                                MapParameter {
                                	name(entry.key)
                                  value(entry.value)
                                }
                              }
                            }
                          }
                      }
                    } catch (Exception e) {
                      println("WARNING: Parameterized Remote Trigger. Fallback to plugin 3.1.5.1 applied")
                    	parameters(step.parameters.collect { entry -> "${entry.key}=${entry.value}" }.join("\n"))
                    }
                  }        
                }
              }
          }
          

          Denis Shvedchenko added a comment - - edited as for documentation, any job that has JobDSL step has left side link to API docs Job DSL API Reference step = [ //credentialsId: "username-passowrd-pair-a" , parameters : [ ABC: '1234' , CDE: 'second value' , NMK: "absolute" ], jobName: "UTILS/provider_old" , remoteJenkins: "etl-test" , token: "test-remote-job" , //disabled: true , abortTriggeredJob: true , enhancedLogging: true , maxConn: 4 ] job( 'example-2' ) { steps { remoteBuildConfiguration { remoteJenkinsName(step.remoteJenkins) job(step.jobName) blockBuildUntilComplete(step.blockBuildUntilComplete?: false ) if (step.pollInterval) pollInterval(step.pollInterval) shouldNotFailBuild(step.shouldNotFailBuild?: false ) preventRemoteBuildQueue(step.preventRemoteBuildQueue?: false ) if (step.token) token(step.token) if (step.disabled) disabled(step.disabled?: false ) if (step.maxConn) maxConn(step.maxConn?:1) if (step.abortTriggeredJob) abortTriggeredJob(step.abortTriggeredJob?: false ) if (step.enhancedLogging) enhancedLogging(step.enhancedLogging?: false ) if (step.credentialsId) auth2 { CredentialsAuth { credentials(step.credentialsId) } } if (step.parameters && step.parameters.size() > 0) { try { parameters2 { MapParameters { parameters{ step.parameters.each { entry -> MapParameter { name(entry.key) value(entry.value) } } } } } } catch (Exception e) { println( "WARNING: Parameterized Remote Trigger. Fallback to plugin 3.1.5.1 applied" ) parameters(step.parameters.collect { entry -> "${entry.key}=${entry.value}" }.join( "\n" )) } } } } }

          Pavel added a comment - - edited

          Thanks for the great example! I could not find one on the web. It will work as a workaround. Unfortunately, the parameters2 still need to be reverse-engineered to get it right. This is not what a general Jenkins user expects or wants.

          I hope the maintainers will fix this problem with JobDSL sooner or later.

          Pavel added a comment - - edited Thanks for the great example! I could not find one on the web. It will work as a workaround. Unfortunately, the parameters2 still need to be reverse-engineered to get it right. This is not what a general Jenkins user expects or wants. I hope the maintainers will fix this problem with JobDSL sooner or later.

          Glad to be helpful.
          But at the end of the day old *parameters(String) works for both cases. and Job DSL only generate interface for stuff written in Plugin, so glad to help you. this implementation allows to unpin 3.1.5.1 and use recent versions .

          and just please explore Job DSL API Reference , it has docs for all installed plugins

          Denis Shvedchenko added a comment - Glad to be helpful. But at the end of the day old *parameters(String) works for both cases. and Job DSL only generate interface for stuff written in Plugin, so glad to help you. this implementation allows to unpin 3.1.5.1 and use recent versions . and just please explore Job DSL API Reference , it has docs for all installed plugins

            cashlalala KaiHsiang Chang
            mcancomert Mehmet Can
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: