20160717 About This Jenkins Blog
20160717 What Jenkins Does
20160224 How To Start Jenkins With Java From Shell
20160717 How To Configure A Job
20160717 How To Install Plug-ins
20160224 How To Block Jenkins Jobs With Lockable Resources
20160221 How To Create The Skeleton Of A Jenkins Plugin With Gradle
20160221 Compile A Hello-World-JPI
20160221 How To Manually Test The Hello-World-JPI With Gradle
20160221 How To Modify the Hello-World-JPI And See The Modification In Jenkins
To know why I write a blog about Jenkins, please read my blog post
I have moved my previous blog entries about Jenkins to this blog, to make it easier for you to find them. Though the time line has changed I think the new order of the entries makes more sense than starting with the details before explaining the big picture.
The Jenkins Wiki explains Jenkins this way :
"Jenkins is an award-winning, cross-platform, continuous integration and continuous delivery application that increases your productivity. Use Jenkins to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by providing powerful ways to define your build pipelines and integrating with a large number of testing and deployment technologies."
The question is, does this help you if you don't know about continuous integration and continuous delivery or if you know about it, but not how it works?
Let me try to explain what Jenkins does and what you can do with Jenkins to setup continuous integration and continuous delivery for your software product.
FYI : Jenkins is a really mighty tool and I don't want to explain every detail and function of Jenkins, I will just mention the basics to explain how to use Jenkins in general.
Master
and any number of Nodes
.You just need to download the Jenkins .war
file and run it with Java, this will create all directories and files for you.
Jenkins can be started standalone with
java -jar jenkins-war-1.649.war
and the jenkins home will be in your home directory in (here with bash)
$HOME/.jenkins
and the default URL is
localhost:8080
FYI : In Jenkins a job is an item.
New Item
Freestyle project
and click OK
Build
tabAdd build step
and select Execute Windows batch command
echo execute my job
Save
Build Now
#1
in the Build History
at the bottom of the jobs pageConsole Output
And there you see something like
[job1] $ cmd /c call C:\Users\amos\AppData\Local\Temp\hudson4614265032990843424.bat
C:\Users\amos\.jenkins\workspace\job1>echo execute my job
execute my job
C:\Users\amos\.jenkins\workspace\job1>exit 0
Finished: SUCCESS
Manage Jenkins
Manage Plugins
Available
tabFilter
Install
column of the plug-in you want to install.Install without restart
It often happens you have to block jenkins jobs, because they are mutual exclusive due to resource usage.
If the amount of your jobs never changes, you can use the Build Blocker Plugin, where you can define with regular expressions, which jobs shall be blocked while other jobs are running.
Adding blockers to some jobs is feasible, but when your number of jobs grows, it becomes a problem, you start repeating yourself, because you have to mutual exclude the new jobs from the old jobs and vice versa.
When this happens, better start using the Lockable Resources Plugin, where you can define resources in
which you can use in your jobs with
Jenkins plugins are usually build with maven but since I know that gradle can handle maven, I thought maybe I don't need to know about how to do it with maven.
Here you find the documentation how to create the JPI skeleton with gradle.
The build.gradle
looks like
buildscript {
repositories {
jcenter()
maven {
url 'http://repo.jenkins-ci.org/releases/'
}
}
dependencies {
classpath 'org.jenkins-ci.tools:gradle-jpi-plugin:0.15.0'
}
}
apply plugin: 'org.jenkins-ci.jpi'
group = "org.jenkins-ci.plugins"
version = "0.0.1-SNAPSHOT" // Or whatever your version is.
description = "A description of your plugin"
jenkinsPlugin {
// Version of Jenkins core this plugin depends on.
coreVersion = '1.420'
// Human-readable name of plugin.
displayName = 'Hello World plugin built with Gradle'
// URL for plugin on Jenkins wiki or elsewhere.
url = 'http://domain.de'
// Plugin URL on GitHub. Optional.
gitHubUrl = 'https://github.com/jenkinsci/some-plugin'
// Plugin ID, defaults to the project name without trailing '-plugin'.
shortName = 'hello-plugin'
// The developers section is optional,
// and corresponds to the POM developers section.
developers {
developer {
id 'developer-id'
name 'firstname lastname'
email 'emailaddress@domain.de'
}
}
}
These are the main tasks you need :
gradle jpi // creates the maven skeleton
gradle build // builds the plugin, find it in build/libs
gradle server // starts a jenkins server on localhost:8080 for testing,
// your plugin is already installed
I have downloaded the Java source from here and saved it in src/main/java/hudson/plugins/
and run gradle build
.
FYI: Manually testing means, we will test the plug-in by using it and looking at its output with a browser. Automatically would mean this is done by a deployment job or it is tested with unit tests.
When you have built your plug-in, you want to use it in jenkins to see it works.
With gradle server
you start a jenkins server where your plug-in is already installed.
You have to create a jenkins job to and use the plug-in there. The hello-world-jpi implements a build step, where it says "Hello, ...", so I added it as build step.
After reading the java source I found out the perform()
function is doing something, so I added a try-catch-block there. Intellij IDEA was a big help, its intellisense gave me some hints to try out.
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
try {
listener.getLogger().println("build.getBuiltOn().getDisplayName() : " +
build.getBuiltOn().getDisplayName());
listener.getLogger().println("build.getBuiltOn().getDescriptor() : " +
build.getBuiltOn().getDescriptor());
listener.getLogger().println("build.getBuildVariables() : " +
build.getBuildVariables());
} catch (Exception e) {
System.out.println(e);
}
return true;
}
FYI: When your jenkins job has no build variables, then the output of the JPI will just be {}
. Enable build variables in jenkins and add a variable as parameter in your job, then it will be printed.
The Blog
|
|
|
|
My Technical Blogs
|
|
|
|
|
|
|
|
|
|
|
|
Projects
|
|
|
|
Blogs Of Friends
|
|
|
|
|
|
CV/About
|
|
|