busy
busy

Reputation: 369

Jenkins & subversion URL with part variable from job name

I have jobs named like:

BUILD--PROJECT--TEMPLATE1
BUILD--PROJECT--TEMPLATE2
BUILD--PROJECT--TEMPLATE3 

Each job is using SCM for subversion for a separate folder/project:

https://svn.domain.com/repos/project/template1/
https://svn.domain.com/repos/project/template2/
https://svn.domain.com/repos/project/template3/

When new job is created we need to update path there manually.

Is it possible to use variables from a job name inside SCM, like:

BUILD--PROJECT--TEMPLATE1
https://svn.domain.com/repos/project/${template, 3rd parameter}/

How would you solve it, any ideas?

Upvotes: 1

Views: 1053

Answers (1)

pkudel4
pkudel4

Reputation: 81

Use the plugins Environment Injector Plugin and the EnvInject API Plugin. Configure them as in the manual.

Inside a job 'general section' tick on "Prepare an environment for the run"

add to the Groovy Script:

return [
JOB_TEMPLATE_NAME: JOB_NAME.split('-').last()
]

In your SCM you define URL like:

https://svn.domain.com/repos/project/${JOB_TEMPLATE_NAME}

If you use SVN_REVISION or SVN_URL global variables, they will be lost. Bug?

My workaround is: add the first build step to execute shell with:

echo "SVN_REVISION=$(svn info | awk '/^Revision:/{print $2}')" >env.properties

In the second build step inject environment variables (plugin) and set 'Properties File Path' to 'env.properties' file created in step 1. Now you can use the SVN_REVISION in other build steps.

Hope this helps!

ciao!

Upvotes: 1

Related Questions