Reputation: 2116
I searched a lot, the GitSCM plugin and stackoverflow etc but could not find answer. I want to checkout Git repository via Jenkins GitSCM plugin into one specific folder say 'MyFolder'.
So if my repository is xyz.git
then after checkout all files of repository should be in MyFolder/*
and NOT in MyFolder/xyz/*
.
To understand more, I want to achieve below (assuming repository is xyz.git) with Jenkins GitSCM plugin. Below command will checkout files in MyFolder
excluding root folder xyz
git clone <REPOSITORY> -- MyFolder
and below command will checkout files in xyz folder
git clone <REPOSITORY>
For reference I am working on below configuration
checkout([$class: 'GitSCM', branches: [[name: gitDefaultBranch]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CleanBeforeCheckout'],[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: gitCreds, url: gitProjectUrl]]])
Please suggest. Versions information:
Upvotes: 5
Views: 18311
Reputation: 1974
You can use the [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'MyFolder/']]
in you checkout code.
Something like below:-
checkout([ $class: 'GitSCM',
branches: [[name: gitDefaultBranch]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanBeforeCheckout'],
[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false],
[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'MyFolder/']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: gitCreds, url: gitProjectUrl]]
])
Upvotes: 8