创建部署问题时,请参考下面模板,你提供的信息越多,越容易及时获得解答。
发帖前请点击 发表主题 右边的 预览(👀) 按钮,确保帖子格式正确。
你只花一分钟创建的问题,不能指望别人花上半个小时给你解答。
如标题,后端的微服务在多个git仓库中,想在一个Jenkinsfile中并行签出所有仓库的代码,Jenkinsfile内容大致如下:
pipeline {
agent {
node {
label 'maven'
}
}
environment {
REGISTRY = '127.0.0.1'
GIT_PREFIX = 'http://127.0.0.1/micro-services'
NAMESPACE = 'test'
DOCKERHUB_NAMESPACE = 'test'
APP_NAME = 'test'
VERSION = '3.1.0.RELEASE'
NACOS_ADDR = '127.0.0.1:8848'
NACOS_NAMESPACE = '49f83c9e-6e19-4940-8771-a66770f54ddd'
ACTIVE_PROFILES = 'test'
}
stages {
stage('default-0') {
parallel {
stage('checkout-test1') {
agent none
when {
expression{
params.APP_NAME =='' || params.APP_NAME.matches("test(.*)")
}
}
steps {
git(url: "$GIT_PREFIX/Test1.git", credentialsId: 'gitlab-id', changelog: true, poll: false, branch: '$BRANCH_NAME')
}
}
stage('checkout-test2') {
agent none
when {
expression {
params.APP_NAME =='' || params.APP_NAME =='test2'
}
}
steps {
git(url: "$GIT_PREFIX/Test2.git", credentialsId: 'gitlab-id', changelog: true, poll: false, branch: '$BRANCH_NAME')
}
}
}
}
}
}
运行时,有时正常,有时报错,报错概率比较高,看起来像是并行签出时有冲突,我该如何在一个Jenkinsfile中并行签出多个git仓库的代码?
Caused by: hudson.plugins.git.GitException: Command "git init /home/jenkins/agent/workspace/test-prod7fvwg/test-prod" returned status code 128:
stdout:
stderr: fatal: cannot copy '/usr/share/git-core/templates/hooks/applypatch-msg.sample' to '/home/jenkins/agent/workspace/test-prod7fvwg/test-prod/.git/hooks/applypatch-msg.sample': File exists
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2380)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2376)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1923)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:995)
... 12 more