Run JJB to define jobs in Jenkins

In post, Setup Jenkins-job-builder on Windows. I installed Jenkins-job-builder (JJB) on my Windows 7 laptop successfully. Now it is time to verify it is working.

1. Add C:\Python27\Scripts into %PATH% parameter so that you can issue ‘jenkins-jobs’ command.

2. Update jenkins-job-builder-0.3.0\etc\jenkins_jobs.ini as below, (Don’t need to bother about the user or password if your Jenkins is not secured)

[jenkins]
user=jenkins
password=Welcome1
url=http://localhost:8080/

3. Create a configuration file

- job:
 name: HelloWorld-YAML-9
 description: 'This job is created by YAML vi Jenkins-job-builder-0.3.0 automatically. Do NOT edit it manually.'
 project-type: freestyle
 block-downstream: false
 scm:
 - git:
 skip-tag: false
 url: https://github.com/velniukas/helloworld.git
 triggers:
 - pollscm: '@hourly'
 builders:
 - ant:
 targets: "debug test install"
 buildfile: "build.xml"
 publishers:
 - junit:
 results: helloworld_junit-result.xml
 - email:
 recipients: luohua.huang@gmail.com

4. Test it.

D:\jenkins-job-builder-0.3.0\etc>jenkins-jobs test HelloWorld-job.yaml -o .

It will create one file named as ‘HelloWorld-YAML9’. It is exactlly the same with how Jenkins defines job.

<?xml version="1.0" ?>
<project>
 <actions/>
 <description>This job is created by YAML vi Jenkins-job-builder-0.3.0 automatically. Do NOT edit it manually.</description>
 <keepDependencies>false</keepDependencies>
 <disabled>false</disabled>
 <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
 <concurrentBuild>false</concurrentBuild>
 <properties/>
 <scm class="hudson.plugins.git.GitSCM">
 <configVersion>2</configVersion>
 <userRemoteConfigs>
 <hudson.plugins.git.UserRemoteConfig>
 <name>origin</name>
 <refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
 <url>https://github.com/velniukas/helloworld.git</url>
 </hudson.plugins.git.UserRemoteConfig>
 </userRemoteConfigs>
 <branches>
 <hudson.plugins.git.BranchSpec>
 <name>**</name>
 </hudson.plugins.git.BranchSpec>
 </branches>
 <disableSubmodules>false</disableSubmodules>
 <recursiveSubmodules>false</recursiveSubmodules>
 <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
 <authorOrCommitter>false</authorOrCommitter>
 <clean>false</clean>
 <wipeOutWorkspace>true</wipeOutWorkspace>
 <pruneBranches>false</pruneBranches>
 <remotePoll>false</remotePoll>
 <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
 <gitTool>Default</gitTool>
 <submoduleCfg class="list"/>
 <relativeTargetDir/>
 <reference/>
 <excludedRegions/>
 <excludedUsers/>
 <gitConfigName/>
 <gitConfigEmail/>
 <skipTag>false</skipTag>
 <scmName/>
 </scm>
 <triggers class="vector">
 <hudson.triggers.SCMTrigger>
 <spec>@hourly</spec>
 </hudson.triggers.SCMTrigger>
 </triggers>
 <builders>
 <hudson.tasks.Ant>
 <buildFile>build.xml</buildFile>
 <targets>debug test install</targets>
 <antName>default</antName>
 </hudson.tasks.Ant>
 </builders>
 <publishers>
 <hudson.tasks.junit.JUnitResultArchiver>
 <testResults>helloworld_junit-result.xml</testResults>
 <keepLongStdio>true</keepLongStdio>
 <testDataPublishers/>
 </hudson.tasks.junit.JUnitResultArchiver>
 <hudson.tasks.Mailer>
 <recipients>luohua.huang@gmail.com</recipients>
 <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
 <sendToIndividuals>false</sendToIndividuals>
 </hudson.tasks.Mailer>
 </publishers>
 <buildWrappers/>
</project>

5. Install it.

D:\jenkins-job-builder-0.3.0\etc>jenkins-jobs –conf jenkins_jobs.ini update HelloWorld-job.yaml
INFO:root:Updating jobs in HelloWorld-job.yaml (None)
INFO:jenkins_jobs.builder:Creating jenkins job HelloWorld-YAML-9

The Jenkins console gets updated as below,
yaml1

However in the Jenkins console it shows a warning message,

It is acceptable to leave unreadable data in these files, as Jenkins will safely ignore it. To avoid the log messages at Jenkins startup you can permanently delete the unreadable data by resaving these files using the button below.

Type Name Error
hudson.model.FreeStyleProject HelloWorld-YAML CannotResolveClassException: hudson.plugins.git.GitSCM

It is because by default git is not installed for Jenkins. Download and install git for windows and configure it.

git1

git2

6. Install it again.

D:\jenkins-job-builder-0.3.0\etc>jenkins-jobs –conf jenkins_jobs.ini update HelloWorld-job.yaml
INFO:root:Updating jobs in HelloWorld-job.yaml (None)
INFO:jenkins_jobs.builder:Creating jenkins job HelloWorld-YAML-9

git3

 

It matches with what I configure in the YAML file.

Project Name: HelloWorld-YAML-9 | Description: This job is created by YAML vi Jenkins-job-builder-0.3.0 automatically. Do NOT edit it manually.

It is using git https://github.com/velniukas/helloworld.git.  | Poll SCM @hourly

Build: Invoke Ant debug test install | JUnit report: helloworld_junit-result.xml

7. The output in Jenkins  & file system

In progressConsole Output

Started by user anonymous
Building in workspace C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository https://github.com/velniukas/helloworld.git
 > C:\Program Files (x86)\Git\bin\git.exe init C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace
Fetching upstream changes from https://github.com/velniukas/helloworld.git
 > C:\Program Files (x86)\Git\bin\git.exe --version
Setting http proxy: http://www-proxy.us.oracle.com:80/
 > C:\Program Files (x86)\Git\bin\git.exe fetch --tags --progress https://github.com/velniukas/helloworld.git +refs/heads/*:refs/remotes/origin/*
 > C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url https://github.com/velniukas/helloworld.git
 > C:\Program Files (x86)\Git\bin\git.exe config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
 > C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url https://github.com/velniukas/helloworld.git
Fetching upstream changes from https://github.com/velniukas/helloworld.git
Setting http proxy: http://www-proxy.us.oracle.com:80/
 > C:\Program Files (x86)\Git\bin\git.exe fetch --tags --progress https://github.com/velniukas/helloworld.git +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/develop
Seen branch in repository origin/master
Seen 2 remote branches
Checking out Revision 1b93141b4a81dd0711fc19479834bb4384dd1937 (origin/develop, origin/master)
 > C:\Program Files (x86)\Git\bin\git.exe config core.sparsecheckout
 > C:\Program Files (x86)\Git\bin\git.exe checkout -f 1b93141b4a81dd0711fc19479834bb4384dd1937
First time build. Skipping changelog.
 > C:\Program Files (x86)\Git\bin\git.exe tag -a -f -m Jenkins Build #1 jenkins-HelloWorld-YAML-9-1
FATAL: Unable to find build script at C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace\build.xml
Build step 'Invoke Ant' marked build as failure
Recording test results
Sending e-mails to: luohua.huang@gmail.com
ERROR: Could not connect to SMTP host: localhost, port: 25
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
	java.net.ConnectException: Connection refused: connect
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)

The code has been pulled down locally from github,

C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace>dir
Volume in drive C is System
Volume Serial Number is 4499-5BD0

Directory of C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace

06/30/2014 01:11 AM <DIR> .
06/30/2014 01:11 AM <DIR> ..
06/30/2014 01:11 AM 128 .gitignore
06/30/2014 01:11 AM 6,739 pom.xml
06/30/2014 01:11 AM 24 README.md
06/30/2014 01:11 AM 91 runtests.sh
06/30/2014 01:11 AM <DIR> src
4 File(s) 6,982 bytes
3 Dir(s) 52,732,325,888 bytes free

C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace>dir src\main
Volume in drive C is System
Volume Serial Number is 4499-5BD0

Directory of C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace\src\main

06/30/2014 01:11 AM <DIR> .
06/30/2014 01:11 AM <DIR> ..
06/30/2014 01:11 AM <DIR> bin
06/30/2014 01:11 AM <DIR> conf
06/30/2014 01:11 AM <DIR> java
06/30/2014 01:11 AM <DIR> scripts
0 File(s) 0 bytes
6 Dir(s) 52,732,325,888 bytes free

C:\Users\luhuang\.jenkins\jobs\HelloWorld-YAML-9\workspace>

 However it fails to run the ‘ant’ target. This is expected as this is a maven project. I tried to update the builders tag with the content from https://github.com/openstack-infra/jenkins-job-builder/blob/master/tests/builders/fixtures/maven-target-doc.yaml however it doesn’t work for my case. I am still checking why.

builders:
        - maven-target:
            maven-version: Maven3
            pom: parent/pom.xml
            goals: clean
            private-repository: true
            properties:
              - foo=bar
              - bar=foo
            java-opts:
              - "-Xms512m -Xmx1024m"
              - "-XX:PermSize=128m -XX:MaxPermSize=256m"
            settings: mvn/settings.xml
            global-settings: mvn/globalsettings.xml