Jenkins管道 - git checkout到工作区中的文件夹而不擦除

时间:2018-01-07 19:26:46

标签: jenkins-pipeline

我想查看我的部署脚本,这些脚本驻留在我的工作区中的部署文件夹的单独repo中。此文件夹中已包含一些文件,问题是在检出脚本期间文件夹被清除。我需要一种方法来保存这些文件。

结帐时使用的代码: ...

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']]]) }

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

如何更改结帐步骤的文件夹?

像这样[已测试]:

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
        }
    }
}

来自git checkout的文件将被放入\speacial_folder_for_git\到您的工作空间中,而此文件夹之外(但位于工作空间中)的其他文件保持不变

答案 1 :(得分:0)

在获取之前存储目录的内容可能很有意义:

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 
}