1. Create repository (using git) and have sample java code.
a. Create a git repository
C:\>mkdir git_repo
C:\>cd git_repo
C:\git_repo>git init
b. Create java code and check-in:
-java code (hw.java). Place it in a subfolder called src in the git repository. The build.xml reads from the src folder
-create ant build file, build.xml
-check-in the java code, build.xml and the src folders into git
2. Create a new pipeline from Admin menu
Goal is to create a hierachical structure like pipeline ==> stage ==> job
Create a new pipeline within the default pipeline group by clicking 'create a new pipeline within this group'
Step #1 : give new pipeline a name
Step #2 : Materials: Material Type =Git
URL = C:/git_repo
Check connection to verify that it was created successfully
Step #3 : Stage/Job
Stage Name = defaultStage
Job Name = defaultJob
Task type = Ant
Task type could be a custom command, say a shell script, which gives more felxibility because now you can run a ant build from the script and also use the echo command to display interim results.
Click Finish and the new pipeline is ready.
Environment variables
-Create an environment variable for the pipeline by going to Admin-->your pipeline-->Ebvironment Variables tab.
JAVA_HOME=C:\Java\jdk1.6.0_27
This variable will be used by ant to compile java code created in #1.
-Add ant bin, git bin to the PATH environment variable by going to Control Panel -->System in Windows.
C:\apache-ant-1.5.2\bin;C:\Program Files (x86)\Git\bin
3. Execute the new pipeline from Pipeline menu
-Lookup the pipeline that was created and click the arrow to trigger execution
-Click defaultJob in left pane
-Select Materials tab. Verify visually that it has the java code (src/hw.java)
-Select Console tab. Scroll down to find the results of run. Verify that there are no errors. If there are no errors , the pipeline will turn green.
Verifying pipeline config by looking up xml
Goto Admin menu and select the 'Source XML' tab.
And make note of the XML for the pipeline
==================================================
<pipeline name="t">
<environmentvariables>
<variable name="JAVA_HOME">C:\Java\jdk1.6.0_27</variable>
</environmentvariables>
<materials>
<git url="c:/git_repo" />
</materials>
<stage name="defaultStage">
<jobs>
<job name="defaultJob">
<tasks>
<ant />
</tasks>
</job>
</jobs>
</stage>
</pipeline>
=== And in Source XML there is only one agent executing =========
<agents>
<agent hostname="RC6186" ipaddress="10.102.100.134" uuid="00c2c460-68ed-4d9b-bce4-c7260f61caa7" />
</agents>
===================================================================
SAMPLE CODE
====== java code ==========
public class hw
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
======= build.xml ===========
<project name="hw" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="hw"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<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}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
=========common git commands ==========
git status
git add build.xml
git commit -m "comming build.xml" -a
git log
Comments
1 comment
Hello Niels!
Can you give us a little more information? Is this happening on a Windows box or a Linux/Unix box? You mentioned that it is running as a service. Is this right?
How did you add git to PATH? For instance, in Windows, it's probably through the "Environment Variables" dialog box. Is this where you added it?
Final question: Is the Go server running as a different user, than the currently logged in user?
Thank you,
Aravind
Please sign in to leave a comment.