Reputation: 53
We want to use a single Jenkins job to build an application.
The solution from How to configure a single Jenkins job to make the release process from trunk or branches? does not work since our SVN structure is different (from historical reasons and we cannot change it):
http://my-svn-repo/projects/
├───branches
│ ├───app1
│ │ ├───BRANCH_A
│ │ ├───BRANCH_B
│ │ └───BRANCH_C
│ ├───app2
│ │ ├───BRANCH_D
│ │ ├───BRANCH_E
│ │ └───BRANCH_F
│ └───app3
│ ├───BRANCH_G
│ ├───BRANCH_H
│ └───BRANCH_I
├───tags
│ ├───app1
│ │ ├───BRANCH_D
│ │ ├───BRANCH_E
│ │ └───BRANCH_F
│ ├───app2
│ │ ├───TAG_D
│ │ ├───TAG_E
│ │ └───TAG_F
│ └───app3
│ ├───TAG_G
│ ├───TAG_H
│ └───TAG_I
└───trunk
├───app1
├───app2
└───app3
The described solution How to configure a single Jenkins job to make the release process from trunk or branches? shows for selection this:
What we would like to have is the following:
Selection 1:
Selection 2 (automatically based on the selection 1, e.g. for app2):
Upvotes: 5
Views: 2700
Reputation: 19906
Use Active Choice Parameter and Groovy script.
APP
to select the application. The Groovy script is expected to return the list of selections, so just return the hard-coded list (or read it from a file or from anywhere you wish):Create parameter VERSION
to select the version.
svn list http://my-svn-repo/projects/tags/appX --username some_name --password some_password
APP
. Whenever the value of APP
is updated, the Groovy script will re-evaluate the choice list using the updated values of referenced parameters. Here is the script for copy & paste:
def svnBaseUrl = 'http://my-svn-repo/projects/'
def versions = ['trunk/' + APP]
def svnTagsUrl = svnBaseUrl + 'tags/' + APP
def command = ['svn', 'list', svnTagsUrl,'--username', 'some_name', '--password', 'some_password']
def proc = command.execute()
proc.waitForOrKill(10000)
if ( proc.exitValue() == 0 ) {
proc.text.eachLine { versions.add('tags/' + APP + '/' + it) }
}
def svnBranchesUrl = svnBaseUrl + 'branches/' + APP
command = ['svn', 'list', svnTagsUrl,'--username', 'some_name', '--password', 'some_password']
proc = command.execute()
proc.waitForOrKill(10000)
if ( proc.exitValue() == 0 ) {
proc.text.eachLine { versions.add('branches/' + APP + '/' + it) }
}
return versions
BASE_SVN_URL=http://my-svn-repo/projects
The script for copy & paste:
#!/bin/bash
echo "================================================"
echo "Parameters for the build:"
echo "Application: $APP"
echo "Base SVN URL: ${BASE_SVN_URL}"
echo "Version: ${VERSION}"
echo "SVN URL: ${BASE_SVN_URL}/${VERSION}"
echo "================================================"
During testing, you may add a line at the end of the script to immediately terminate your job and just see the values:
exit 1
Build-application-core-job
, which will perform the actual build. Pass the job all the necessary parameters:Upvotes: 6
Reputation: 3256
You can use one or booth of the plugins below.
1 - Dynamic Extended Choice Paramenter This seems to make exactly what you want but I never use this one.
2 - Dynamic Parameter In this you can configure a script to read all app's, branch or trunks and transform this on choices options for your job or just add a list of static options.
Upvotes: 1