使用 Jenkins 管道将多个 git 存储库签出到同一个作业中 [英] Using a Jenkins pipeline to checkout multiple git repos into same job

查看:24
本文介绍了使用 Jenkins 管道将多个 git 存储库签出到同一个作业中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jenkins Multiple SCM 插件将三个 git 存储库检出到我的 Jenkins 作业中的三个子目录中.然后,我执行一组命令,使用从所有三个存储库中提取的信息和代码构建一组工件.

I'm using the Jenkins Multiple SCM plugin to check out three git repositories into three sub directories in my Jenkins job. I then execute one set of commands to build a single set of artifacts with information and code drawn from all three repositories.

Multiple SCM 现在已折旧,文中建议移至管道.我试过了,但我不知道如何让它工作.

Multiple SCM is now depreciated, and the text recommends moving to pipelines. I tried, but I can't figure out how to make it work.

这是我希望从 Jenkins 作业目录的顶层看到的目录结构:

Here is the directory structure I'm interested in seeing from the top level of my Jenkins job directory:

$ ls
Combination
CombinationBuilder
CombinationResults

这三个子目录中的每一个都有一个检出的 git repo.对于 Multiple SCM,我使用了 git,然后添加了结帐到子目录"行为.这是我对管道脚本的尝试:

Each of those three sub-directories has a single git repo checked out. With the Multiple SCM, I used git, and then added the "checkout to a subdirectory" behavior. Here was my attempt with a pipeline script:

node('ATLAS && Linux') {
    sh('[ -e CalibrationResults ] || mkdir CalibrationResults')
    sh('cd CalibrationResults')
    git url: 'https://github.com/AtlasBID/CalibrationResults.git'
    sh('cd ..')
    sh('[ -e Combination ] || mkdir Combination')
    sh('cd Combination')
    git url: 'https://github.com/AtlasBID/Combination.git'
    sh('cd ..')
    sh('[ -e CombinationBuilder ] || mkdir CombinationBuilder')
    sh('cd CombinationBuilder')
    git url: 'https://github.com/AtlasBID/CombinationBuilder.git'
    sh 'cd ..'

    sh('ls')
    sh('. CombinationBuilder/build.sh')
}

然而,git 命令似乎在工作区的顶级目录中执行(这有点道理),而且根据语法,似乎没有 checkout-to-sub-directory 行为.

However, the git command seems to execute at the top level directory of the workspace (which makes some sense), and according to the syntax too, there doesn't seem to be the checkout-to-sub-directory behavior.

推荐答案

您可以使用 dir 命令在子目录中执行流水线步骤:

You can use the dir command to execute a pipeline step in a subdirectory:

node('ATLAS && Linux') {
    dir('CalibrationResults') {
        git url: 'https://github.com/AtlasBID/CalibrationResults.git'
    }
    dir('Combination') {
        git url: 'https://github.com/AtlasBID/Combination.git'
    }
    dir('CombinationBuilder') {
        git url: 'https://github.com/AtlasBID/CombinationBuilder.git'
    }

    sh('ls')
    sh('. CombinationBuilder/build.sh')
}

这篇关于使用 Jenkins 管道将多个 git 存储库签出到同一个作业中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆