我在启动时自动将GitHub组织添加到我的Jenkins实例,但是当它添加每个作业时它会执行它。这导致许多作业被执行,长时间(小时)阻塞构建队列。有没有办法通过Jenkinsfile导入每个项目,但不能自动运行构建?
启动Jenkins实例时,我正在运行以下代码:
import jenkins.branch.OrganizationFolder
import org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait
import org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator
import org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait
import org.jenkinsci.plugins.github_branch_source.GitHubConfiguration
import static jenkins.model.Jenkins.instance as jenkins
static Boolean organisationFolderExists(String name) {
def folders = jenkins.items
if (folders.isEmpty()) {
return false
}
def organisation = folders.find { folder -> folder.name == name }
return organisation
}
String lookupApiUri(def apiEndpoint) {
GitHubConfiguration gitHubConfig = GitHubConfiguration.get()
gitHubConfig.getEndpoints().findResult { it.name == apiEndpoint ? it.apiUri : null }
}
void createOrganisationFolder(def config) {
def folder = jenkins.createProject(OrganizationFolder, config.name)
folder.displayName = config.displayName
folder.description = config.description
GitHubSCMNavigator navigator = new GitHubSCMNavigator(config.name)
navigator.credentialsId = config.project.scanCredentials
navigator.apiUri = lookupApiUri(config.project.apiEndpoint)
navigator.traits = [
new jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait(config.project.repositoryNamePattern, ''),
new jenkins.scm.impl.trait.RegexSCMHeadFilterTrait('.*'),
new BranchDiscoveryTrait(3),
new OriginPullRequestDiscoveryTrait(3),
]
folder.navigators.replace(navigator)
jenkins.save()
folder.scheduleBuild(0)
}
if (!organisationFolderExists(config.name)) {
createOrganisationFolder(config)
}
这成功创建了组织,但我需要一种方法来阻止每个构建执行。这是连接到我们的内部GitHub Enterprise实例。