Innocentspirit
Innocentspirit

Reputation: 23

Configure block in Jenkins pipelinejob using DSL?

Trying to write a DSL Jenkins pipeline job using jobs-dsl and not sure if I'm hitting a couple of pipeline job limitations or am missing something more fundamental.

1 - Configuring "Polling ignores commits in certain paths" under "Additional Behaviours" using the configure block does not seem to be working as expected in the pipeline job; I have tested and this configure block works as expected in a freestyle job dsl. Searched and couldn't find anything relevant - can someone confirm if the below is supported/not supported within the below pipeline job?

    pipelineJob("ProjA/pipeline") 
    {
        logRotator
        {
          daysToKeep 10
          numToKeep 30
        }
        definition 
        {
          cpsScm 
          {
            scm
            {
                git('[email protected]:sample-org/pipeline.git', '*/develop')
            }
            configure { gitScm -> 
                gitScm / 'extensions' << 'hudson.plugins.git.extensions.impl.PathRestriction' {
                    excludedRegions('sample/dirs')
                }
              }
           }
        }
     }

2 - How do we pass credentials to the git under scm block under pipeline? Works for freestyle jobs but having trouble getting it to work here

Thanks in advance.

Upvotes: 0

Views: 2527

Answers (2)

daspilker
daspilker

Reputation: 8194

The built-in DSL only supports basic options. But the Dynamic DSL supports almost any option.

pipelineJob('example') {
  definition {
    cpsScmFlowDefinition {
      scm {
        gitSCM {
          userRemoteConfigs {
            userRemoteConfig {
              url('[email protected]:sample-org/pipeline.git')
              name('master')
              refspec(null)
              credentialsId('example')
            }
          }
          branches {
            branchSpec {
              name('*/develop')
            }
          }
          extensions {
            pathRestriction {
              includedRegions(null)
              excludedRegions('sample/dirs')
            } 
          }
          doGenerateSubmoduleConfigurations(false)
          browser {}
          gitTool(null)
        }
      }
      scriptPath('Jenkinsfile')
    }
  }
}

Upvotes: 4

xxxvodnikxxx
xxxvodnikxxx

Reputation: 1277

FYI for normal pipeline

Git checkout using credentials referring to the git plugin step :

    stage('checkout') {
        git credentialsId: '<credentialsID from credentials plugin>',
        url: '[email protected]/repoName.git',
        branch: 'master' 
    }

Reg. scm plugin step

 stage('checkout') {
     checkout scm: [$class: 'GitSCM',
        userRemoteConfigs: [[url: 'https://repository.foo/git/fooRepoName.git' ,
            credentialsId: 'credentialsIDToUseFromCredentialsPlugin']],
            branches: [[name:'refs/tags/TAGNAME']]],
        poll:false      
 }

stage('checkout') {
     checkout scm: [$class: 'GitSCM',
        userRemoteConfigs: [[url: 'https://repository.foo/git/fooRepoName.git' ,
            credentialsId: 'credentialsIDToUseFromCredentialsPlugin']],
            branches: [[name:'BRANCHNAME']]],
        poll:false      
 }

And I was never looking for poll if it works or not

Upvotes: 1

Related Questions