简体   繁体   English

Jenkins工作中的脚本编写

[英]Scripting within Jenkins job

Main problem: 主要问题:

In the Jenkins build, I have a variable GIT_BRANCH of this content: origin/feature/JIRA1-add-component-A . 在Jenkins版本中,我有一个变量GIT_BRANCH ,其内容如下: origin/feature/JIRA1-add-component-A

From it I would like to obtain another variable with the value: %3Aorigin%2Ffeature%2FJIRA1-add-component-A 从中我想获得另一个变量,其值为: %3Aorigin%2Ffeature%2FJIRA1-add-component-A

For this, I need scripting. 为此,我需要脚本。 How can I do scripting in the job definition? 如何在职位定义中编写脚本?

Context & further explanation: 上下文及进一步说明:

From Jenkins, for every pull request that my project has, I am creating an instance of a project in SonarQube. 从詹金斯(Jenkins),对于我的项目提出的每个拉取请求,我都在SonarQube中创建一个项目实例。

For example, if I have a pull request from branch origin/feature/JIRA1-add-component-A , I am creating a project with the following URL: 例如,如果我有来自分支origin/feature/JIRA1-add-component-A的拉取请求,那么我将使用以下URL创建一个项目:

http://localhost:9000/dashboard?id=com.my.package%3Amy-project%3Aorigin%2Ffeature%2FJIRA1-add-component-A http:// localhost:9000 / dashboard?id = com.my.package%3Amy-project%3Aorigin%2Ffeature%2FJIRA1-add-component-A

I am using the Quality Gates plugin to fail the build in case the code's quality(as seen by SonarQube)is not good. 我使用Quality Gates插件使构建失败,以防代码的质量(如SonarQube所示)不好。

The problem is that Quality Gates needs my SonarQube project name, so in this case com.my.package%3Amy-project%3Aorigin%2Ffeature%2FJIRA1-add-component-A . 问题是Quality Gates需要我的SonarQube项目名称,因此在本例中为com.my.package%3Amy-project%3Aorigin%2Ffeature%2FJIRA1-add-component-A

However, I can only specify it like this: 但是,我只能这样指定:

com.my.package:my-project:${GIT_BRANCH}

Which translates into this: 转换为:

com.my.package:my-project:origin/feature/JIRA1-add-component-A

Something like this? 像这样吗 Apologize if not, but dead tired lol. 如果没有道歉,但很累,哈哈。

def GIT_BRANCH = "origin/feature/JIRA1-add-component-A"
def BRANCH = "%A3" + "${GIT_BRANCH}".replace("/", "%2F")
println "${BRANCH}"

I'm sure it can be done easier BUT: 我敢肯定,这可以轻松完成,但:

Pre: origin/feature/JIRA1-add-component-A 上一个:来源/功能/ JIRA1-add-component-A

Post: %A3origin%2Ffeature%2FJIRA1-add-component-A 帖子:%A3origin%2Ffeature%2FJIRA1-add-component-A

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

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