How to configure Jenkins in order to build project

2019-06-28 06:59发布

There's too much routine with building next project version using ant. The routine is in several properties files that must be edited before running ant task. I took a look at Jenkins as a system to make builds (including night ones) but I have a problem with changing properties.

Is it possible (if yes, how can I do it) to type parameters in Jenkins configuration before build in order they will be passed to ant?

What I really mean is the following schema (I used in manual builds):

  • there're 2 properties files that contain data about build version, src destination, emails to notify about new build and so on.

  • corresponding properties' keys are used in Ant tasks and these properties are changed manually before build.

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

  • there're also 3 or 4 ant XMLs that a imported in build.xml, and these xmls also read properties from mentioned files.

What I want to do is:

  • change key properties in Jenkins

  • press build project

  • my data will overwrite data in properties files OR will be passed as ant vars values straight to the ant's task(s).

  • as a result I receive new build with corresponding notifications (they're made through ant)

Are there mechanisms that allow one to make such schema work via Jenkins?

Thank you in advance.

标签: ant jenkins
2条回答
不美不萌又怎样
2楼-- · 2019-06-28 07:30

In Jenkins, you can use the parameterised build feature to specify those parameters you need to substitute into your build.

For example, if specify a parameter called server and, when clicking "Build Now", you enter test, the build will be executed with an environment variable you can access called ${server}.

Then, in your "Invoke Ant" build step, if you press Advanced..., this reveals a "Properties" field. Here you can enter my.ant.property=${server}.
That's equivalent to calling ant -Dmy.ant.property=${server}, and will be expanded to ant -Dmy.ant.property=test.

查看更多
够拽才男人
3楼-- · 2019-06-28 07:30

Another option : Set environment variables for the scope of the build using this Env plugin. So if the properties you are using are environment variables or can be set as them then you want to use this one. Though it might involve some effort in changing the build scripts, but it can be a good option :

Q : Why would I use this one as I already have parametrized build plugin

A : Because the parametrized build plugin requires human interaction if there is more than 1 choice. For example building for Release 1 or Release 2 or Test branch.

While in the Env plugin, you can set the property once for each choice and then create a respective job for each. Then just schedule the job(s) thereby eliminating the human factor.

查看更多
登录 后发表回答