gpt4 book ai didi

java - 如何相对于子目录运行 Jenkins 管道?

转载 作者:太空宇宙 更新时间:2023-11-04 09:51:54 28 4
gpt4 key购买 nike

我有一个 git 存储库,其中有 2 个模块。一种是基于 SpringBoot 的后端模块,另一种是基于 VueJS 的前端模块。

app-root
- backend
- frontend

我有一个声明式风格的 Jenkinsfile 来使用相关的 Maven 命令构建我的后端模块。我想从 backend 目录中执行所有这些 Maven 命令。

一种选择是对所有命令分别使用 dir("backend") { ....} ,这对我来说看起来很难看。

还有其他选项可以指示 Jenkins 从子目录内执行整个管道吗?

最佳答案

我最终进入了“准备项目”阶段,将子目录内容放入根目录中。

删除所有根内容(“干净”阶段)可能也是一个好主意,以绝对确保以前的版本没有残留。

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'
}
}
}

关于java - 如何相对于子目录运行 Jenkins 管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54630870/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com