CloudBees Jenkins Certified Engineer

Jenkins-Logo

Last week I Passed my CloudBees Jenkins Certified Engineer Exam.
It was not an easy exam by any stretch. The few of the questions were very long. I took all the time to finish the exam.

While preparing for the exam, I created a Gitbook. Folks preparing for the exam will find it very useful.

https://www.gitbook.com/book/muralibala/cloudbees-certified-jenkins-engineer-2017/details

Other very useful resources:

jeanne’s experiences with the jenkins certification beta exam


https://memefected.gitbooks.io/studying-for-the-jenkins-engineer-certification/content/
https://ankiweb.net/shared/info/1993369597

Getting started with Jenkins Rest API

Jenkins-Logo

Before we can access Jenkins API, we need grab the API key associated with your account.

  • Login into your Jenkins instance.
  • Click on Manage Jenkins
  • Scroll down to find Manage Users and click on the link.
  • Under your username, click on the gear.
  • Under API token, click on the “Show API Token…”
  • Other way to get to the Configure link is using this URL : http://[Jenkins Instance]:8080/me/configure
  • Copy the API token, you would need this information while making API calls to Jenkins Rest API
  • Now your are ready to test the API and run few command.

Oh! One other thing you need to do before you could curl up. Navigate to Manage Jenkins>>Configure Global Security and uncheck the box “Prevent Cross Site Request Forgery exploits”. I don’t know why but you need to uncheck this before you could run the POST commands below. Some useful information here – http://stackoverflow.com/questions/16738441/how-to-request-for-crumb-issuer-for-jenkins

Lets open the Shell or command prompt. I am using SampleFreeStyleJob for the Jenkins Project.

Trigger a build:
curl -X POST http://[Jenkins_Instance]:8080/job/SampleFreeStyleJob/build --user [USER_NAME]:[API_TOKEN]

Retrieve a project config.xml file
curl http://[Jenkins_Instance]:8080/job/SampleFreeStyleJob/config.xml --user [USER_NAME]:[API_TOKEN]

Disable a project
curl -X POST http://[Jenkins_Instance]:8080/job/SampleFreeStyleJob/disable --user [USER_NAME]:[API_TOKEN]

Enable a project
curl -X POST http://[Jenkins_Instance]:8080/job/SampleFreeStyleJob/enable --user [USER_NAME]:[API_TOKEN]

More Examples

> curl http://[Jenkins_Instance]:8080/api/json?pretty=true --user [USER_NAME]:[API_TOKEN]
> curl -g http://[Jenkins_Instance]:8080/api/json?pretty=true&tree=jobs[name,color] --user [USER_NAME]:[API_TOKEN]
> curl -g http://[Jenkins_Instance]:8080/job/[Job Name]/config.xml -o config.xml [USER_NAME]:[API_TOKEN]

Top 5 Jenkins CI Tips you should know.

Jenkins-Logo

1. Tell Jenkins to run a specific project on a particular slave node

Set the “Restrict where this job can be run” check box in your job configuration and specify the name of your slave. If you add more slaves later, you can set labels for each slave and specify those in your job configs.

2. Restart Jenkins manually

You can use either of the following commands:

http://(jenkins_url)/safeRestart – Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.

http://(jenkins_url)/restart – Forces a restart without waiting for builds to complete.

You can even use the SafeRestart Plugin. Super useful tool.

Finally, via CLI:

  • sudo service jenkins start – To start the Jenkins
  • sudo service jenkins stop – To stop the Jenkins
  • sudo service jenkins restart – To restart the Jenkins
  • sudo service jenkins status – To know the status of Jenkins

3. Locked out of Jenkins

If you don’t have a lot of other configuration that you’d like to save, you can just delete %JENKINS_HOME%/config.xml and restart Jenkins to disable security. Otherwise, edit config.xml and set the values inside the useSecurity tags to false, then restart Jenkins.

I had this exact issue today on my Windows Jenkins server. Just removing the XML file and restarting did not work for me. So I had to:

  • Stop the service.
  • Check Task Manager to ensure the process is gone.
  • Edit the Config.XML file and change the useSecurity false (or you could delete the config.xml file).
  • Start the service again.

4. Default shell environment valuables
To get the list of all the variables that are available to shell scripts:

http://(jenkins_url)/env-vars.html

5. Jenkins Directory Structure

jenkins-directory_structure

Ref: https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins

Installing Jenkins on AWS EC2

Jenkins-Logo

Jenkins is an open source automation server software that allows continuous integration. Read more about it here.

We are going to install Jenkins on AWS EC2 instance. If you have not already done so, please login into your AWS account and launch an EC2 instance with RHEL OS. For more information on how to launch an instance, please read this post.

1) Install the latest stable packages, then reboot.

sudo yum update -y

2) Before you can install Jenkins, you need to setup a JVM.

sudo yum install java-1.8.0-openjdk.x86_64

3) After the installation, you can confirm it by running the following command:

java -version

Jenkins require Java 1.6 or more than. If Java version is less than 1.6 than we have to upgrade the Java. Follow the instruction here on installing Java

4) Install wget

sudo yum install wget -y

5) Install Jenkins

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins -y

6) Start the Jenkins service and set it to run at boot time:

sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

6) Install firewalld (if not already installed)

sudo yum install firewalld -y

8) After install unmask, enable and start the firewall with below commands

sudo systemctl unmask firewalld
sudo systemctl enable firewalld
sudo systemctl start firewalld

9) In order to allow visitors access to Jenkins, you need to allow inbound traffic on port 8080. You can either open port 8080 in AWS Console or run the following command:

sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

10) Finally, visit the following address from your web browser to confirm your installation:

http://[your-jenkins-server-IP:8080]

or by running the following command

sudo netstat -ntulp | grep 8080

If the site does not load, please check the Jenkins log file for more information

Linux
By default, logs are here /var/log/jenkins/jenkins.log (unless customized in /etc/default/jenkins (for *.deb) or via /etc/sysconfig/jenkins (for */rpm)

Windows
By default, logs are here %JENKINS_HOME%/jenkins.out and %JENKINS_HOME%/jenkins.err (unless customized in %JENKINS_HOME%/jenkins.xml)

More information can be found here.

Moving forward, you will need the Jenkins Initial Password to get started:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Oh! And one last thing – If you wish to change Jenkins HTTP port number from the default port 8080, you need to change the file /etc/sysconfig/jenkins

sudo vi /etc/sysconfig/jenkins

Good luck!

33 Top Tools and Resources for Software Projects

Startup Tools

Working on a new start-up? Below is my list of must-have Top Tools and Resources for Software Projects. These are the some of the tools that I have enjoyed using in the past. Please feel to add your own in the comments.

Requirement Gathering

  • User story is a tool used in Agile software development to capture a description of a software feature from an end-user perspective. The user story describes the type of user, what they want and why.
    Check out – http://www.storyboardthat.com/articles/software-development/agile-user-stories
  • Mind Map is a diagram used to visually organize information. A mind map is often created around a single concept, drawn as an image in the center of a blank page, to which associated representations of ideas such as images, words and parts of words are added. Major ideas are connected directly to the central concept, and other ideas branch out from those. Mind maps can be drawn by hand, either as “rough notes” during a lecture, meeting or planning session, for example, or as higher quality pictures when more time is available. Check out – http://www.mindmapping.com/

Text Editor
Bracket is a modern, open source text editor that understands web design. Honestly, I have tried couple of editors in the past like Sublime, NotePad++, TextPad, etc. but by far Bracket is the best.

Mockup tools
My all time favorite is  Balsamiq. Click here for an article from mashable – 9 Excellent Tools for Design Mockups. Also, check out MockFlow (design UI workflows). I have heard good reviews about them. Another similar tool, I have used is GenMyModel . Worth giving it a shot.

Project Management
The best in my experience for small team Project Management and Todo tasks is Basecamp. Basecamp’s unique blend of tools is everything any team needs to stay on the same page about whatever they’re working on. Check it out – https://basecamp.com/

Database Design
You can use locally hosted tool like SQL Management Studio or SQL Developer to design, develop and maintain databases or you could online tools like Vertabelo.

Web Dev, Debug and API Tools

  • JSFiddle is an online playground to code and share code, this time with many flavors of JavaScript. Check it out – http://jsfiddle.net/
  • Koding is a software development in an online environment with lots of social activity. It’s StackExchange + Facebook + Cloud9 + Virtual Machines + a few other things. It’s a great idea and worth a try. Check it out – https://koding.com/
  • Regular expression tester with syntax highlighting, contextual help, video tutorial, reference, and searchable community patterns. Check it out – http://regexr.com/
  • Firebug is a free and open-source web browser extension for Mozilla Firefox that facilitates the live debugging, editing, and monitoring of any website’s CSS, HTML, DOM, XHR, and JavaScript. This one tool i cannot live without – http://getfirebug.com/whatisfirebug
  • Fiddler is a free web debugging proxy for any browser, system or platform. Check it out – http://www.telerik.com/fiddler
  • Rest API – One of the best testing REST API services is Postman. Please give it a try at https://www.getpostman.com/. Another super cool Firefox extension I have used before and love it is RestClient for Firefox. And of course I cannot miss out on swagger.io API Framework.

Team Messaging
Slack brings all your communication together in one place. It’s real-time messaging, archiving and search for modern teams.

Task Management
Trello is the free, flexible, and visual way to organize anything with anyone.

Issue Tracking
Undoubtedly the best in this space is Atlassian Jira.

Version Control
Stash (Bitbucket) – Git, your way. See what makes Bitbucket the Git solution for professional teams.

SourceTree is a free Mercurial and Git Client for Windows and Mac that provides a graphical interface for your Hg and Git repositories.

Build Tools
Integration build tools have plenty to do. They fetch software from the SCM, figure out dependencies, compile everything to make the deliverable product, package it up, and even deploy to test servers. Few nice Integration tools include:

IDEs in the Cloud
IDEs are traditionally used locally, on the developer’s workstation; however, some companies, including Cloud9, Compilr, and Nitrous, want developers to use their hosted IDEs in the cloud.

Continuous Integration (CI)
Per Wikipedia, Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies to a shared mainline several times a day. It was first named and proposed by Grady Booch in his 1991 method,[1] although Booch did not advocate integrating several times a day. It was adopted as part of extreme programming (XP), which did advocate integrating more than once per day, perhaps as many as tens of times per day.

The CI server that everyone has heard of is Jenkins, but there are plenty more. Others include JetBrain’s TeamCity, CruiseControl, and Atlassian’s Bamboo. CI servers are also available as cloud services. Hosted CI has the added challenge of connecting with other hosted services. Codeship and Travis can all read from GitHub and write to Heroku.

Really useful links:
What are some great online tools for startups?
Top Startup Tools
Startup Tools by Steve Blank