Jenkins combines ant transfer parameters

Source: Internet
Author: User

  Requirements :

Using the "parameterized build process" of Jenkins, the user manually enters the parameters. This parameter is received by the ant script and output (of course, the middle can also be complex, here to illustrate the problem, only the simple output).

1. Basic Environment

Jenkins1.509.4 (now Jenkins has been upgraded to 2.x, the version difference is not very large)

apache-ant-1.9.6

apache-tomcat-7.0.6 (Note: Jenkins is placed in Tomcat and can refer to my "Jenkins default workspace and change default Workspace" article)

The prerequisite is that the JDK is already supported and configured with the relevant environment variables ~

2. Analysis of Ideas

work One : Select the parameterized build process when configuring the job in Jenkins and select String Parameter.

work two : Write a class with the Main method and print this parameter.

work three (important work): connect inputs and outputs. This can be done through an ant script. The ant script can also pass parameters when executed with the command line.

Now tidy up your mind: jenkins"parameterized build process" input parameters →jenkins execute the ant script and pass the parameters to the ant script →ant script to compile, package, and execute the classes that contain the main method.

3. Start training

Description :

    The actual process could be: work two → work one → work three.

3.1 Work One

3.2 Work Three

Note: CD javaant is because the Build.xml file will be placed under this directory, see:

Here's a very important point of knowledge: How do I build jobs locally in Jenkins?

The answer is to copy the entire project directly under Jenkins ' workspace. For example, my Jenkins default workspace has been changed to E:\jenkins\, where a directory src-usercreate is created to build a local job.

3.3 Work Two

directly on the code.

1  Packagecom.primeton.ant;2 3  Public classHelloWorld {4 5     /**6      * @paramargs7      */8      Public Static voidMain (string[] args) {9String Version = Args[0];TenSystem.out.println ("Hello," +version+ "!")); One     } A  -}
Java Code
1<?xml version= "1.0" encoding= "UTF-8" standalone= "no"?>2<project name= "Javaant" basedir= "." default= "main" >3 4<property name= "Src.dir" value= "src"/>5<property name= "Build.dir" value= "Build"/>6<property name= "Classes.dir" value= "${build.dir}/classes"/>7<property name= "Jar.dir" value= "${build.dir}/jar"/>8<property name= "Main-class" value= "Com.primeton.ant.HelloWorld"/>9<property name= "code_version" value= "v1.2.2"/>Ten<target name= "clean" > One<deletedir= "${build.dir}"/> A</target> -  -<target name= "Compile" > the<mkdir dir= "${classes.dir}"/> -<javac srcdir= "${src.dir}" destdir= "${classes.dir}"/> -</target> -  +<target name= "Jar" depends= "compile" > -<mkdir dir= "${jar.dir}"/> +<jar destfile= "${jar.dir}/${ant.project.name}.jar" basedir= "${classes.dir}" > A<manifest> at<attribute name= "Main-class" value= "${main-class}"/> -</manifest> -</jar> -</target> -  -<target name= "Run" depends= "jar" > in<java jar= "${jar.dir}/${ant.project.name}.jar" fork= "true" > -<arg value= "${code_version}"/> to</java> +</target> -  the<target name= "Clean-build" depends= "Clean,jar"/> *  $<target name= "main" depends= "Clean,run"/>Panax Notoginseng  -</project>
Ant Script

The entire Java Engineering directory hierarchy is as follows:

Note: As mentioned above, the entire project (including build.xml) needs to be copied to Jenkins's workspace directory (mine is E:\jenkins\src-usercreate\).

3.4 Build Results

Click "Build Now" in Jenkins for the job to perform the following results:

4. Summary

①jenkins"parameterized build process" for user input parameters.

The ②ant script can pass the above parameters to the Java code as an intermediary [pay attention to understanding the pass-through process of this parameter].

Jenkins combines ant transfer parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.