2013年9月19日木曜日

Setting up a HelloWorld Java project with Git and Jenkins under 5 minutes

What is assumed

  • Java is installed
  • Git is installed
  • Jenkins is installed

1. Create a HelloWorld java program



$ mkdir hello


$ emacs HelloWorld.java (or Notepad HelloWorld.java on Windows)


public class HelloWorld {
  public static void main (String[] args) {
    System.out.println("Hello World !!");
  }



$ emacs run.sh (Let's create a script to compile and run. Its Notepad run.bat on Windows)


javac HelloWorld.java
java HelloWorld


$ run.sh (execute the script you just created. Its run.bat on Windows)

2. Create a Git repository for HelloWorld source



$ git init


$ git add HelloWorld.java run.sh


$ git commit -m "created"


$ git log

3. Create a Jenkins job to get latest code from the Git repository and then build and run HelloWorld project



1. In Jenkins, bring up "Manage Plugins" screen




2. Make sure that Jenkins GIT plugin is installed. If not, install it.




3. Create a new Jenkins Job.



Name this job "git_test".


4. In the job configuration page, choose Git for "Source Code Management" and then set "Repository URL" point to your Git repository.




To figure out a string to put in to "Repository URL" box, see my local path to the Git repository can compare with you environment.

[tsuyoshi_watanabe@ywatanabe hello]$ pwd
/home/tsuyoshi_watanabe/sandbox/gittest/hello


5. Add run.sh script as a new build step





4. Putting all together

Choose "Build Now" for our newly created job.






Now, Jenkins hit our Git repository to clone a temporary source tree, and then execute our "run.sh" script.

0 件のコメント:

コメントを投稿