Jenkins使用变量$ {GIT_BRANCH}作为sonarqube参数,不包含“origin /”。 [英] Jenkins build using variable ${GIT_BRANCH} as sonarqube parameter without "origin/"

查看:1618
本文介绍了Jenkins使用变量$ {GIT_BRANCH}作为sonarqube参数,不包含“origin /”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



scm工具设置用于获取与此名称对应的每个分支:'feature-branch - *'这对Maven构建来说非常完美。
我想建立sonarqube,因此它会为每个实际的git分支使用不同的分支,但是sonarqube不允许使用通配符。
然而它确实允许变量,所以我尝试了 $ {GIT_BRANCH} ,但是这个变量保存:'origin / feature-branch-214' ,sonarqube不会将其识别为有效的分支名称。 Sonarqube期望'feature-branch-214'



因此,我需要在sonarqube分支中放置 $ {GIT_BRANCH} 的子字符串不包含'origin /'部分。

解决方案

您可以创建一个新变量并赋值:

 `echo $ {GIT_BRANCH} | cut -d'/'-f 2-`

之后,您将可以使用新的变量在Jenkins Git Branch SonarQube参数中,按照以下步骤操作。

步骤

在build部分,使用命令添加 Execute Shell 步骤:

  echo NEW_VAR =`echo $ {GIT_BRANCH} | cut -d'/'-f 2 -`> newfile 

然后添加一个注入一个环境变量步骤属性文件路径

  newfile 
code>

在SonarQube配置中,保留分支字段并在其他属性字段中添加以下内容:

  -Dsonar.branch = $ {NEW_VAR} 

上述解决方案不是很干净,但我已经证实它可以工作


Large team with separate git branches per team and sonar as a code quality checker.

The scm tool is set up to pick up every branch that corresponds to this name: 'feature-branch-*' which works perfectly, for the maven build.
I wanted to set up sonarqube so it would use a different branch for every actual git branch, but sonarqube does not allow wildcards. It does however allow variables so I tried ${GIT_BRANCH}, but this variable holds: 'origin/feature-branch-214', which sonarqube does not recognise as a valid branch name. Sonarqube expects 'feature-branch-214'

So I need something to put there (in sonarqube branch) that does a substring of the ${GIT_BRANCH} to exclude the 'origin/' part.

解决方案

You could create a new variable and assign the value:

`echo ${GIT_BRANCH} | cut -d'/' -f 2-`

Afterwards, you will be able to use the new variable in the Jenkins Git Branch SonarQube parameter, by following the below steps.

Steps

In build section add an Execute Shell step with command:

echo NEW_VAR=`echo ${GIT_BRANCH} | cut -d'/' -f 2-` > newfile

Then add an Inject an environment variable step with Properties File Path:

newfile

In SonarQube configuration leave the branch field empty and add the following in the Additional properties field:

-Dsonar.branch=${NEW_VAR}

The above solution is not very clean but I've verified that it works

这篇关于Jenkins使用变量$ {GIT_BRANCH}作为sonarqube参数,不包含“origin /”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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