TEQ

Tech Docs

Get started with Jenkins. Installation with blue ocean theming and basic job creation.

Jenkins is the leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

Download and install Jenkins

Download latest Jenkins from https://jenkins.io/download/
As I have a Debian based distro and the latest version available by the time I’m writing this is 2.174, This doc shares installation of Jenkins 2.174 on Debian based distros.

cd ~ 
wget https://pkg.jenkins.io/debian/binary/jenkins_2.174_all.deb

Once file is downloaded, Install it.

sudo apt install ./jenkins_2.174_all.deb

Note: If Java is not installed, It will give you an error. So, Install java if not installed, then try installing Jenkins again.

sudo apt install openjdk-8-jdk

Jenkins will be listening on port 8080, So we can configure Nginx as a reverse proxy. So, Install Nginx.

sudo apt install nginx

Create a new nginx configuration file and make sure you have a domain like jenkins.example.com pointed to the IP. Find the Nginx conf file bellow.

server {
 
    listen 80;
    server_name jenkins.example.com;
     
    location / {
 
      proxy_set_header        Host $host:$server_port;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
 
      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:8080;
      proxy_read_timeout  90;
 
      proxy_redirect      http://127.0.0.1:8080 http://jenkins.example.com;
  
      # Required for new HTTP-based CLI
      proxy_http_version 1.1;
      proxy_request_buffering off;
      # workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
      add_header 'X-SSH-Endpoint' 'jenkins.example.com:50022' always;
 
 
 
 
    }
  }

Now browse http://jenkins.example.com it will ask you for Administrator password. Get it from /var/lib/jenkins/secrets/initialAdminPassword

Now, you will see a ‘Customize Jenkins’ dashboard, where you can choose Plugins to be installed. Select and install plugins according to your requirements.

Create a first Admin user now. It’s recommended not to choose username as admin in any application.

Install Blue Ocean Plugin : Optional

For a Better UI/UX install Blue ocean plugin.

Go to Manage Jenkins > Manage Plugins > Available
Then search for ‘Blue Ocean’ and install it. Once installation is completed. Add following rule to Nginx conf to have Blue Ocean as default theme when accessing http://jenkins.example.com

if ( $http_referer ~ ^(?!http://jenkins.example.com) ) {
  rewrite ^/$ http://jenkins.example.com/blue/organizations/jenkins last;
} 
Create Jobs

Jobs are at the heart of the Jenkins build process. Simply put, you can think of a Jenkins job as a particular task or step in your build process. This may involve simply compiling your source code and running your unit tests. Or you might want a job to do other related tasks, such as running your integration tests, measuring code coverage or code quality metrics, generating technical documentation, or even deploying your application to a web server. A real project usually requires many separate but related jobs.

To create your first simple job go to New Item > Free Style Project > Choose a name > OK

Select GIT in ‘Source Code Management’ Section and give your git repo URL there.

Add build scripts in the Build section, and click save. Now go to http://jenkins.example.com/blue/organizations/jenkins/pipelines where you can see your first build job. Run it. You are all set with your first Jenkins Job.

You might get issue if jenkins user don’t have an ssh key. In that case please generate a key and try to access your git repo from terminal.

su jenkins
ssh-keygen

Issuing ssh-keygen will need to provide multiple ‘Enter’ and then copy the /var/lib/jenkins/.ssh/id_rsa.pub and add the key in your GIT account. Then try to access your repo.

 git ls-remote -h [email protected] HEAD

Try creating Jenkins jobs according to your requirements. I will be publishing some advanced job configurations for Jenkins soon. Stay tuned.!