简体   繁体   English

Jenkins 中的多分支管道与 SVN

[英]Multibranch Pipeline in Jenkins with SVN

I have SVN as my SCM.我有 SVN 作为我的 SCM。 The SVN Root URL structure is as follows. SVN Root URL 结构如下。 https://svn.domain.com/orgName https://svn.domain.com/orgName

Under this, I have a folder called "test".在此之下,我有一个名为“test”的文件夹。 Then I have tags, branches and trunk.然后我有标签、树枝和树干。 For example, https://svn.domain.com/orgName/test/trunk例如, https://svn.domain.com/orgName/test/trunk
https://svn.domain.com/orgName/test/branches https://svn.domain.com/orgName/test/branches

Under trunk and branches, I have various modules.在主干和分支下,我有各种模块。 One module is Platform which is the core module.一个模块是平台,它是核心模块。 The URL structure for my project under Platform is as follows.我的项目在 Platform 下的 URL 结构如下。

https://svn.domain.com/orgName/test/trunk/Platform/MyProject https://svn.domain.com/orgName/test/branches/Platform/1.0.0.0/MyProjecthttps://svn.domain.com/orgName/test/trunk/Platform/MyProject https://svn.domain.com/orgName/test/branches/Platform/1.0.0.0/MyProject

Not sure if the above structure is correct or not.不确定上面的结构是否正确。 But this is how it is structured in my organization and it can't be changed.但这就是它在我的组织中的结构方式,无法更改。 Now, I have the following questions.现在,我有以下问题。

  1. At what level should I maintain the Jenkinsfile?我应该在什么级别维护 Jenkinsfile?
  2. How should I pass the branch name (including trunk) to this file?我应该如何将分支名称(包括主干)传递给这个文件?

It will be great if someone can provide some details (if possible step by step) on how to use Multibranch pipeline with SVN.如果有人可以提供有关如何将 Multibranch 管道与 SVN 一起使用的一些详细信息(如果可能的话),那将会很棒。 Unfortunately, I could not find any tutorial or examples to achieve this.不幸的是,我找不到任何教程或示例来实现这一点。

I figured this out on my own.这是我自己想出来的。 Here are the details, in case, someone needs help.这是详细信息,以防万一有人需要帮助。

For Trunk, add the Jenkinsfile inside trunk/Platform (in my case) and for Branches, add Jenkinsfile inside branches/Platform/ folder.对于主干,在主干/平台(在我的情况下)中添加 Jenkinsfile,对于分支,在分支/平台/文件夹中添加 Jenkinsfile。 For branches, it is better to keep the Jenkinsfile inside each version folder since it has some benefits.对于分支,最好将 Jenkinsfile 保存在每个版本文件夹中,因为它有一些好处。 This approach will create a Jenkins job for each version.这种方法将为每个版本创建一个 Jenkins 作业。

In the Jenkins job (for multibranch pipeline), add the base url for Project Repository Base.在 Jenkins 作业(用于多分支管道)中,添加 Project Repository Base 的基本 URL。 In my case, it is https://svn.domain.com/orgName/test .就我而言,它是https://svn.domain.com/orgName/test In Include branches field, add trunk/Platform, branches/Platform/* in my case.在包括分支字段中,在我的情况下添加主干/平台、分支/平台/*。 In Jenkinsfile, to get branch name, use the built in variable $BRANCH_NAME.在 Jenkinsfile 中,要获取分支名称,请使用内置变量 $BRANCH_NAME。 This gives trunk/Platform for trunk and branches/Platform/1.0.0.0 (for example) for branches.这为主干提供了主干/平台,为分支提供了分支/平台/1.0.0.0(例如)。

Only challenge is that job names are created like Trunk/Platform, Branches/Platform/1.0.0.0.唯一的挑战是创建的作业名称如 Trunk/Platform、Branches/Platform/1.0.0.0。 So the workspace gets created like Trunk%2FPlatform, Branches%2FPlatform%2F1.0.0.0 since "/" gets encoded with %2F.因此,工作区的创建类似于 Trunk%2FPlatform, Branches%2FPlatform%2F1.0.0.0,因为“/”使用 %2F 进行编码。 While using in jobs, make sure the job name is appropriately modified using the below code.在作业中使用时,请确保使用以下代码适当修改作业名称。

def cws = "${WORKSPACE_DIR}\\" + "${JOB_NAME}".replace("%2F","_").replace("/","\\")
echo "\u2600 workspace=${cws}"
def isTrunk = "${JOB_NAME}".toLowerCase().contains("trunk")
def version = ""
def verWithBldNum = ""
echo "\u2600 isTrunk=${isTrunk}"
if(!isTrunk)
 {
    version = "${JOB_NAME}".substring("${JOB_NAME}".lastIndexOf("%2F") + 3, "${JOB_NAME}".length())
    echo "\u2600 version=${version}"
    verWithBldNum = "${version}".substring(0, "${version}".lastIndexOf('.') + 1) + "${BUILD_NUMBER}"
    echo "\u2600 verWithBldNum=${verWithBldNum}"
 }
else
{
    echo "\u2600 Branch is Trunk"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM