How to Trigger builds remotely in Jenkins? | Jenkins Tutorials | scmGalaxy

trigger-builds-remotely-in-jenkins
How to Trigger builds remotely in Jenkins?
1. Create a user – You need to create a user in jenkins using you would like to trigger a jenkins jobs from remote loction or script
How to create users in Jenkins?
Manage Jenkins –> Manage Users –> Create User
2. Assign a right privillage to the specific user?
How to assign privillage to the user?
Manage Jenkins –> Configure Global Security –> Enabled “Anyone can do anything”
OR
Manage Jenkins –> Configure Global Security –> Configure “Matrix-based security” for the specific users and assign atleast following Permissions.
Overall – Read
Job – Build
Job – Read
Job – Workspace
3. Find out jenkins user “API Token”
How to find jenkins user “API Token”?
Click on the user name located at top right(e.g http://54.171.140.1:8080/user/admin1/) –> Configure –> Locate the “API Token” section.
4. Enabled “Trigger builds remotely” in Jenkins Job Configuration.
Click on the desired job –> Configure –> Locate the “Trigger builds remotely” under “Build Triggers” Tab
Enabled the check box of “Trigger builds remotely”
Provide some Authentication Token e.g – iFBDOBhNhaxL4T9ass93HRXun2JF161Z
$ Save
5. Formulate the command to run using curl. 
> curl –user userid:API-Token http://IP OR HOST:PORT/job/JOB_NAME/build?token=Authentication_Token
eg.curl –user admin1:91367cf0389eaf89669f74c9963c9fb3 http://54.171.140.1:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z
Some of other formats which is being tried in google but need to be tested with specific users. there are working with “Anonymous”
> curl -X POST http://admin1:91367cf0389eaf89669f74c9963c9fb3@54.171.140.1:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z

> wget http://admin1:91367cf0389eaf89669f74c9963c9fb3@54.171.140.1:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z

WORKING WITH NEW JENKINS
> wget –auth-no-challenge –user=admin –password=5ad344f0518640f62d0483084bb889bc http://13.126.143.49:8080/job/ANT//build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z

If you are using wget 1.11 against Jenkins version 1.586 and above with the JENKINS-25169 fix, you might need to use the following options:
wget –auth-no-challenge –http-user=user –http-password=apiToken –secure-protocol=TLSv1 http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN

If you are using wget 1.11, you might need to use the following options:
wget –auth-no-challenge –http-user=user –http-password=apiToken http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN

With wget 1.10.x the following is enough (but will not work with 1.11.x) :
wget http://user:apiToken@jenkins.yourcompany.com/job/your_job/build?token=TOKEN

If you are a Windows User!
‘gitbash’ is a program combined of git and bash. A bash is shell that runs commands once you type the name of command and press enter. 🙂
Download  the git bash from here https://git-scm.com/download/win and install it.
Tagged : / / / / / / /

Generate Jenkins Job Configuration Automatically | Jenkins Tutorials

generate-jenkins-job-configuration-automatically
Generate Jenkins Job Configuration Automatically?
Job DSL Plugin
The job-dsl-plugin allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.
More –
Multi-Branch Project Plugin
This plugin adds additional project types that create sub-projects for each branch using a shared configuration.
Job Generator Plugin
This plugin adds a new job type “Job Generator” which can generate new projects when executed.
Jenkins Job Builder
Jenkins Job Builder takes simple descriptions of Jenkins jobs in YAML or JSON format and uses them to configure Jenkins. You can keep your job descriptions in human readable text format in a version control system to make changes and auditing easier. It also has a flexible template system, so creating many similarly configured jobs is easy.
More –
Generating New Jenkins Jobs From Templates and Parameterised Builds
We use Jenkins to run our builds in a continuously. This is great, but you still have to do a fair bit of configuration each time you set up a new job. If you have a fairly static set of builds this isn’t a problem. We found ourselves in a situation where we had to create a lot of very similar builds quite regularly. Creating a new job by hand and manually changing the 10 or so tiny little things in each build is a pain and error prone. So…automate that too!
More
Tagged : / / / / / / /

How to Install Jenkins using Docker | Step by step guide | scmGalaxy

Step 1: Installing Docker
$ apt-get install docker (Ubuntu)
$ yum install docker  (RHEL/CENTOS)
Step 2:  First, pull the official jenkins image from Docker repository.
$ docker pull jenkins 

Step 3: Next, run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkins_home from the container is mapped to jenkins/ directory from the current path on the host. Jenkins 8080 port is also exposed to the host as 49001.

Mapping port 8080 on the host to the container (the web ui), port 50000 to port 50000 (for build agents). Run with `-p 50000:50000` so you can connect JNLP slaves. For port 50000. This is to handle connections from JNLP based build slaves. This will store the workspace in /var/jenkins_home. All Jenkins data lives in there including plugins and configuration.

$ docker run -d -p 8080:8080 -p 50000:50000 jenkins 
This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user – uid 1000) or use -u some_other_user parameter with docker run.
$ docker run -d -p 8080:8080 -p 50000:50000 -u root -v $PWD/jenkins:/var/jenkins_home jenkins 
 Other Example:
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins -u root 
This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user – uid 1000) or use -u some_other_user parameter with docker run. This information is also found in the Dockerfile. So all you need to do is to ensure that the directory $PWD/jenkins is own by UID 1000:
$ mkdir jenkins
$ chown 1000 jenkins
$ docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins
How to see the Jenkins log?
$ docker exec name tail -f /var/log/jenkins/jenkins.log
Where name = --name 
Step 3:  Access to j=Jenkins
As we have successfully run Jenkins Container, we can browse Jenkins Web Interface using our Web Browser by pointint to http://ip-address:49001 or http://localhost:49001 according to the configuration.
Tagged : / / / / / / / / / / / / /

Jenkins useful websites references | Jenkins Resources | scmGalaxy

jenkins-useful-websites-reference
Tagged : / / / / / / / / / /

Jenkins Backup and Restore Process | Jenkins Tutorial

jenkins-backup-and-restore-process

How Do I Backup Jenkins Jobs using Grunt?

Backup Jenkins configuration to S3

bash-backup-script for jenkins‘ job-configs via user-crontab

Backup and restore Jenkins using jenkins plugins

Tagged : / / / / / / / / / / / / / / / /

How to Resolve jenkins java.lang.outofmemoryerror permgen space issues?

jenkins-java-lang-outofmemoryerror-permgen-space-issues

Solution 1

In Windows: Go to environment variable and add following variables

export JAVA_OPTS=”-XX:MaxPermSize=512m -Xms512m -Xmx1024m”
export GRADLE_OPTS=”-XX:MaxPermSize=512m”
export SONAR_RUNNER_OPTS=”-Xmx512m -XX:MaxPermSize=512m”

In Linux:
In my ~/.bash_profile file, I have set the following 3 variables. Note there are other variables in this file as well i.e. JAVA_HOME, ANT_HOME, SONAR_HOME, SONAR_RUNNER_HOME, etc:

export JAVA_OPTS=”-XX:MaxPermSize=512m -Xms512m -Xmx1024m”
export GRADLE_OPTS=”-XX:MaxPermSize=512m”
export SONAR_RUNNER_OPTS=”-Xmx512m -XX:MaxPermSize=512m”

Solution 2
You can set the -Xmx or -XX:MaxPermSize in your Jenkins global configuration. To do this, navigate to Jenkins global configuration page (Manage Jenkins -> Configure System)

Name – JAVA_OPTS
Value – “-XX:MaxPermSize=512m -Xms512m -Xmx1024m”

You can set similarlity for maven, gradle, sonar as well under “Maven Project Configuration” or grade project configuration.

Name – GRADLE_OPTS
Value – “-XX:MaxPermSize=512m”

Solution 3

They way you can modify this value depends on the distribution and depending on the slave type

Master

In RedHat, for example, you can do it under /etc/sysconfig/jenkins using the variable JENKINS_JAVA_OPTIONS… i.e JENKINS_JAVA_OPTIONS=”-XX:MaxPermSize=512m”.
In Ubuntu, the Jenkins configuration file is under /etc/default/jenkins and the variable to configure is JAVA_ARGS … i.e JAVA_ARGS=”-XX:MaxPermSize=512m”.

Slave

Sometimes slave machines will require permgen to be increased. Depending on the type of slave that is configured will require a different method for setting any java argument.

With SSH Slaves, the java process is started using an SSH command, so the “-XX:MaxPermSize=512m” can be set in the JVM Options in the Node configuration page.
With JNLP Slaves launching as a service on linux, you can add the VM arguments to the startup scripts (usually in /etc/sysconfig/jenkins or /etc/default/jenkins as part of the JAVA_ARGS variable)
With JNLP Slaves launching as a service on Windows requires modifications to be made on the jenkins.xml file which is located on slave machine in the JENKINS_HOME directory.

Reference
http://stackoverflow.com/questions/18000841/jenkins-java-lang-outofmemoryerror-permgen-space
https://wiki.jenkins-ci.org/display/JENKINS/Builds+failing+with+OutOfMemoryErrors
https://cloudbees.zendesk.com/hc/en-us/articles/204264000-Why-do-I-receive-java-lang-OutOfMemoryError-PermGen-space
http://stackoverflow.com/questions/14762162/how-do-i-give-jenkins-more-heap-space-when-its-running-as-a-daemon-on-ubuntu
http://stackoverflow.com/questions/18000841/jenkins-java-lang-outofmemoryerror-permgen-space
http://javarevisited.blogspot.nl/2011/09/javalangoutofmemoryerror-permgen-space.html
https://plumbr.eu/outofmemoryerror/permgen-space

Tagged : / / / / / / / / /

Jenkins Troubleshooting Guide

jenkins-troubleshooting

Jenkins Troubleshooting

Jenkins is one of the important CI tools which many organization used as part of their Build and DevOps infrasture. I am going to consolidate all the troubshooting techniques which can be used in order to find any issues related in jenkins.

Step 1. Take a look at Log generated by the jenkins and plugins via http://jenkins-master/log

Note: Here you can also create your own logger and and set your custom log levels such as (severe, warning, info, config, file, finer, finest, all)

Step 2. Also, you can look at /var/log/jenkins/jenkins.log via doing “tail -f /var/log/jenkins/jenkins.log” and check carefully whats breaking it.

Log file in windows – jenkins.err.log & jenkins.out.log

Slave log file in windows – logs\slaves

Step 3. Check the system log file

Step 4. Few Jenkins plugins which can you help you
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring

Step 4. Make sure your Jenkins & installed plugins version is installed with most uptodate stable release.

Some Common issues:
Issues 1. If Jenkins hangs, follow https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+is+hanging

Issues 2 Site is down with no 404 messages
Cause- Jenkins had an Out of Memory (OOM) error causing the server to kill the jenkins instance
Solution: Restart server; Review heap logs to identify root cause of error

Issues 3 Site is up however no jobs are displayed
Cause 1: AWS Server rebooted but data volume did not mount properly
Solution: mount <device> <path> on the instance

Issues 4 – java.lang.outofmemoryerror permgen space issues

Solution – http://www.scmgalaxy.com/scm/build-workflow-management/jenkins/jenkins-java-lang-outofmemoryerror-permgen-space-issues.html

Tagged : / / / / / / / / /