Jenkinfile DSL how to specify the target directory

I am learning Jenkins 2.0 piping. So far, my file is pretty simple.

node { stage "checkout" git([url:"https://github.com/luxengine/math.git"]) stage "build" echo "Building from pipeline" } 

I cannot find a way to set the directory in which git will be checked. I also cannot find any documentation related to this. I found https://jenkinsci.imtqy.com/job-dsl-plugin/ , but it doesn't seem to match what I see in other tutorials.

+7
jenkins jenkins-pipeline
source share
4 answers

Explanation

It looks like you are trying to set up a Pipeline job (formerly known as Workflow). This type of job is very different from Job DSL .

The purpose of the Pipeline job is to:

Organizes lengthy activities that can span multiple slaves. Suitable for the construction of pipelines (formerly called workflows) and / or the organization of complex events that do not easily fit into the type of work in a free style.

Where as a DSL job:

... allows you to program the creation of projects using DSL. Pressing a job creation in a script allows you to automate and standardize your Jenkins installation, unlike everything that was before.

Decision

If you want to check your code for a specific directory, replace git with the more general SCM checkout step. The final Pipeline configuration should look like this:

 node { stage "checkout" //git([url:"https://github.com/luxengine/math.git"]) checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'checkout-directory']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/luxengine/math.git']]]) stage "build" echo "Building from pipeline" } 

As a future reference for Jenkins 2.0 and Pipeline DSL, please use the built-in fragment generator or documentation .

+12
source share

This can be done using the dir directive:

 def exists = fileExists '<your target dir>' if (!exists){ new File('<your target dir>').mkdir() } dir ('<your target dir>') { git url: '<your git repo address>' } 
+2
source share

First clarify that you are using the Jenkins Job DSL.

You can do it like this:

  scm { git { wipeOutWorkspace(true) shallowClone(true); remote { url("xxxx....") relativeTargetDir('checkout-folder') } } } 

This address above allows you to simply enter the upper left edge, for example, "scm", and it will show in which cases you can use the "scm" relationship. Than you can select "scm-freestylejob" and then press "***" to see the details.

The common starting point for the Jenkins Job DSL is here:

You can, of course, ask here about SO or the Google Forum:

+1
source share

You are using the Pipeline Plugin , not the Job DSL Plugin . In the Pipeline plugin, if you want to determine something where there is not yet a function available in the Pipeline syntax, you can define it yourself .

0
source share

All Articles