How to configure Jenkins to create a project using ant and custom arguments

Too much routine with building the next version of a project using ant. The routine is in several properties files that must be edited before running the ant task. I looked at Jenkins as a system for creating (including nightly ones), but I have a problem with changing properties.

Is it possible (if yes, how to do this) for entering parameters in the Jenkins configuration before assembly, so that they are passed to ant?

What I really mean is the following diagram (I used in manual assemblies):

  • There are 2 properties files that contain information about the version of the assembly, destination src, e-mail messages to notify you of a new assembly, etc.

  • keys of the corresponding properties are used in ant tasks, and these properties are changed manually before assembly.

  • some properties are read by Java util and used for their own part at build time.

  • there are also 3 or 4 ant XML that are imported in the build.xml file, and these xmls also read properties from the specified files.

What I want to do:

  • change key properties in Jenkins

  • click assembly project

  • my data will overwrite the data in the properties files OR will be transferred as ant values โ€‹โ€‹of vars directly to the ant task.

  • As a result, I get a new assembly with corresponding notifications (they are done through ant)

Are there mechanisms to work with such a scheme through Jenkins?

Thanks in advance.

+4
source share
2 answers

In Jenkins, you can use the parameterized assembly function to specify the parameters that you need to replace in your assembly.

For example, if you specify a parameter with the name server , and when you click "Create Now" you enter test , the assembly will be performed with an environment variable that you can access: ${server} .

Then, in the "Invoke Ant" step, if you click Advanced ... , this will open the "Properties" field. Here you can enter my.ant.property=${server} .
This is equivalent to calling ant -Dmy.ant.property=${server} and will expand to ant -Dmy.ant.property=test .

+9
source

Another option: Set environment variables for the build area using this Env plugin . Therefore, if the properties you use are environment variables or can be set as them, then you want to use this. Although this may require some effort when changing build scripts, it may be a good option:

Q: Why should I use this one since I already have a parameterized build plugin

A: Since the parameterized assembly plugin requires human interaction, if there is more than one choice. For example, building for Release 1 or Release 2 or Test branch.

So far, in the Env plugin, you can set the property once for each selection, and then create the corresponding task for each. Then simply plan the task, thereby eliminating the human factor.

+2
source

All Articles