bsky
bsky

Reputation: 20222

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.

From it I would like to obtain another variable with the value: %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.

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:

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.

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.

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

Upvotes: 0

Views: 101

Answers (1)

T. Putters
T. Putters

Reputation: 59

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

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

Upvotes: 1

Related Questions