I would like to check out my deployment scripts which reside in separate repo to the deployment folder in my workspace. This folder already has some files in it, and the problem is that during the checkout of the scripts the folder gets cleared. I need a way to keep these files.
The code used for checkout: ...
steps{
checkout(
[$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'deployment']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'secret', url: 'https://bitbucket.org/secret/deploy_scripts.git']]])
}
Any help will be appreciated!
There is a way to clean up a workspace in Jenkins. You need to install the Workspace Cleanup Plugin. This plugin can clean up the workspace before build or after a build. Under Build Environment, check the box that says Delete workspace before build starts.
Login to Jenkins, click on “Manage Jenkins” > “Manage Plugins” > Click on the “Available” tab then search for “workspace cleanup“. You will see various plugins listed. Click on the checkbox for “Workspace Cleanup“, plugin then click on install without reboot tab below the page.
cleanWs : Delete workspace when build is done.
What about changing folder for checkout step?
like this [tested]:
node(){
stage("checkout"){
// `dir` step will create folder in workspace, if it is not exist
dir('speacial_folder_for_git'){
//git checkout here
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'alexkh_git_credentials', url: 'http://localhost:7990/scm/tes/mytestrepo.git']]]
}
// change current directory back, to workspace:
dir('')
{
//do your job out of git folder
}
}
}
Files from git checkout
will be placed in \speacial_folder_for_git\
into your workspace, while other files outside this folder (but inside workspace) remains untouched
It could make sense to stash a content of the directory before fetching:
steps{
sh "mkdir -p deployment;touch deployment/test"
stash name: "deployment", includes: "deployment/**"
checkout(
[$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'deployment']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'secret', url: 'https://bitbucket.org/secret/deploy_scripts.git']]])
unstash deployment
sh "ls deployment"
# it prints fetched repo AND existing before files
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With