gpt4 book ai didi

git - Jenkins 管道如何与 monorepo 一起工作

转载 作者:太空狗 更新时间:2023-10-29 13:25:05 28 4
gpt4 key购买 nike

我对 Jenkins 很陌生。我的存储库是一个 monorepo - 包含两个子项目,web_appnative_app。我想使用 Jenkins 作为 CI 引擎,这样每次代码推送到 repo 时,Jenkins 都会自动帮助执行构建-测试-交付工作流程。

我创建了一个管道项目,直觉上我应该创建两个 Jenkinsfile,每个都在相关文件夹下,即:

web_app/
|-Jenkinsfile
native_app/
|-Jenkinsfile

但是,我很快意识到这会导致问题 - 我需要为几乎每个阶段/步骤更改工作目录。尝试过

stage('Build') { 
steps {
sh 'cd ./web_app/'
sh 'ls'
sh 'git pull'
}
}

但不起作用,工作目录没有改变。

我还没有找到一种有效的方法来更改整个管道的工作区,并且担心这种 monorepo 结构将来会导致 Jenkins 出现更多问题。我应该拆分这个存储库,还是有一些方便的方法来更改工作目录?

最佳答案

您可以使用 dir 步骤来更改步骤 block 的目录。您的示例代码如下所示:

stage('Build') {
dir('web_app') {
sh 'ls'
sh 'git pull'
}
}

Documentation of the dir step

dir: Change current directory

Change current directory. Any step inside the dir block will use this directory as current and any relative path will use it as base path. path

Type: String

关于git - Jenkins 管道如何与 monorepo 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47878217/

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