我正在使用GitLab。给定多个目录,例如文件夹1,文件夹2,文件夹3。我只希望仅在folder1下有任何更改的情况下运行作业。是否有人能够获得includedRegions以在Jenkins管道工作中工作。
checkout(
[
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'PathRestriction', excludedRegions: '', includedRegions: 'folder1/.*']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'user', url: 'ssh://something/experiment.git']]
]
)
答案 0 :(得分:0)
如果使用管道,则在构建启动后执行结帐步骤。
管理此问题的唯一方法是使用常规检查变更集,如果包含的目录中没有更改,则跳过构建。
答案 1 :(得分:0)
我设法使其正常运行。由于结帐将在我们的Jenkins中的各个项目中使用,因此我编写了共享库以使其易于使用。
示例:strToSparseCheckout.groovy
#!/usr/bin/env groovy
import hudson.plugins.git.extensions.impl.SparseCheckoutPath
def call(paths) {
def list = paths.split('\n')
def sparsePaths = []
def isDefaultAdded = false
list.each {
def path = it - '/.*'
def sparsePath = new SparseCheckoutPath(path)
sparsePaths.push(sparsePath)
}
return sparsePaths
}
示例:sparseCheckout.groovy
#!/usr/bin/env groovy
def call(Map namedargs) {
checkout(
[
$class: 'GitSCM',
branches: [[name: "${namedargs.branch}"]],
extensions: [
[$class: 'LocalBranch', localBranch: '**'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: "${namedargs.target_dir}"],
[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: strToSparseCheckout("${namedargs.included_regions}")],
[$class: 'PathRestriction', excludedRegions: """${namedargs.excluded_regions}""", includedRegions: """${namedargs.included_regions}"""]
],
userRemoteConfigs: [[credentialsId: 'user', url: "${namedargs.url}"]]
]
)
}
在管道中,我们可以调用sparseCheckout共享库。
pipeline {
stage('Checkout') {
sparseCheckout(
[
url: 'ssh://path.to.git/something.git',
branch: 'refs/heads/master',
target_dir: 'something',
excluded_regions: "${params.excluded_regions}",
included_regions: "${params.included_regions}"
]
)
}
}