6

Here is my job DSL which creates pipelinejob in which script is taken from scm itself.

pipelineJob ("${jobName}_deploy") {
  description("built by seed")

definition {
     cpsScm {
        scm {
            git {
                remote {
                    url('gitUrl')
                    credentials('user_creds')
                }
              branch('master')
            }
        }
        scriptPath "scripts/pipeline/jenkinsfile_deploy"
    }
 }
 }

I need the lightweight checkout should be checked automatically. enter image description here

any help would be more appreciated. I have so many jobs in which i need to open each and every job and click that check box which is painful.

ryan1506
  • 175
  • 1
  • 2
  • 17

3 Answers3

5

You can use a Configure Block to add any option that is missing in the built-in DSL:

pipelineJob('example') {
  definition {
    cpsScm {
      // ...
    } 
  }
  configure {
     it / definition / lightweight(true)
  }
}
daspilker
  • 8,154
  • 1
  • 35
  • 49
0

I tried to use Configure Block for lightweight() but it does not work for me.

The thing I did to solve this issue is to use cpsScmFlowDefinition() like this:

pipelineJob('example') {
  definition {
    cpsScmFlowDefinition {
      scm {
        gitSCM {
          userRemoteConfigs {
            userRemoteConfig {
              credentialsId('')
              name('')
              refspec('')
              url('')
            }
          }
          branches {
            branchSpec {
              name('')
            }
          }
          extensions {
            cleanBeforeCheckout()
            localBranch {
              localBranch('')
            }
          }
          doGenerateSubmoduleConfigurations(false)
          browser {
            gitWeb {
              repoUrl('')
            }
          }
          gitTool('')
        }
      }
      scriptPath('')
      lightweight(true)
    }
  }
}
Summit
  • 13
  • 1
  • 7
0

As per this wiki, this has to be like this

pipelineJob('job-name') {

  description('''
Job description
''')

  definition {
    cpsScm {
      lightweight(true)
      scm {
        git {
          remote {
            url('git@github.com:arulrajnet/attila.git')
            credentials('CREDENTIAL_ID')
          }
          branches('*/master')
        }
      }
      scriptPath('build.groovy')
    }
  }
}
arulraj.net
  • 4,579
  • 3
  • 36
  • 37