2 回答

TA贡献1785条经验 获得超4个赞
我最终进入了一个“准备项目”阶段,将子目录内容放入根目录。
删除所有根内容(阶段“清理”)以绝对确保没有以前构建的剩余部分也可能是一个好主意。
node {
def dockerImage
stage('clean') {
sh "rm -rf *"
}
stage('checkout') {
checkout scm
}
// need to have only 'backend' subdir content on the root level
stage('prepare project') {
// The -a option is an improved recursive option, that preserve all file attributes, and also preserve symlinks.
// The . at end of the source path is a specific cp syntax that allow to copy all files and folders, included hidden ones.
sh "cp -a ./backend/. ."
sh "rm -rf ./backend"
// List the final content
sh "ls -la"
}
stage('build docker image') {
dockerImage = docker.build("docker-image-name")
}
stage('publish docker image') {
docker.withRegistry('https://my-private-nexus.com', 'some-jenkins-credentials-id') {
dockerImage.push 'latest'
}
}
}

TA贡献2041条经验 获得超4个赞
您可以在后端和前端模块中拥有 jenkinsfiles,并在每个管道上指向它们,例如:
在管道本身上,您只需cd到子模块并执行其命令:
pipeline {
agent any
stages {
stage('build') {
steps {
sh 'cd backend'
sh 'mvn clean package'
}
}
//other stages
}
}
如果您不想cd使用子模块,则可以使用稀疏签出,但在这种情况下,您必须相应地更改 jenkinsfile 的路径,因为它将位于根文件夹中。
添加回答
举报