我有一个用子模块组织的项目kuma:
我想在Jenkins中配置一个多分支管道来监视kumascript repo上的分支,以便:
git submodule update --init
)这可能吗?有更好的方法吗?
答案 0 :(得分:0)
这对我有用。
首先,在结账前从提交中读取Jekinsfile
,因此很容易使用kumascript
子模块中的那个,并且更难(不可能?)从中读取它一个不同的回购。
在使用Git插件3.4.1的Jenkins 2.68中,我设置了一个多分支管道。一个来源是Git,指向kumascript存储库:
"发现分支机构"在存储库中查找分支并为它们启动构建。
"擦除存储库并强制克隆"解决了jgit
在检出子模块之前没有获取子模块存储库的问题,因此目标提交不可用。它会导致Jenkins日志中出现如下错误:
> git fetch --no-tags --progress https://github.com/mdn/kumascript +refs/heads/*:refs/remotes/origin/*
Checking out Revision 998d9e539127805742634ef1c850221cf04ca2c7 (build-with-locales-1340342)
org.eclipse.jgit.errors.MissingObjectException: Missing unknown 998d9e539127805742634ef1c850221cf04ca2c7
at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:158)
at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:227)
at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:859)
at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:772)
此问题似乎在https://issues.jenkins-ci.org/browse/JENKINS-45729中报告,并在Git客户端插件2.5.0中得到修复。
清除repo似乎强制完全获取,在父项目中安装时可能是必要的。
Jenkins现在配置为为存储库中的每个分支创建一个构建。要将其作为子模块进行检查,需要在Jenkinsfile中手动检出父项目。我使用了Jenkin" Pipeline Syntax"帮助构建命令的工具
经过一些格式化后,我的Jenkinsfile:
stage("Prepare") {
// Checkout Kuma project's master branch
checkout([$class: 'GitSCM',
userRemoteConfigs: [[url: 'https://github.com/mozilla/kuma']],
branches: [[name: 'refs/heads/master']],
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
doGenerateSubmoduleConfigurations: false,
submoduleCfg: []
])
// Checkout KumaScript in subfolder
dir('kumascript') {
checkout scm
}
}
这将检出kuma
项目及其子模块,然后使用" vanilla" checkout检出所请求的分支,但是在子模块目录中:
从那时起,如果我想在kuma
repo中运行一个命令,我就运行它:
stage('Build') {
sh 'make build-kumascript VERSION=latest'
}
如果我想在kumascript
子模块中运行它,我将其包装在dir
中:
stage('Lint') {
dir('kumascript') {
sh 'make lint VERSION=latest'
sh 'make lint-macros VERSION=latest'
}
}