Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to execute grovvy script remotely on Jenkins server?

A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/.

curl example via bash

curl -d "script=<your_script_here>" https://jenkins/script
# or to get output as a plain text result (no HTML)
curl -d "script=<your_script_here>" https://jenkins/scriptText

curl submitting groovy file via bash

curl --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

curl submitting groovy file providing username and password via bash

curl --user 'username:password' --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh.

java -jar jenkins-cli.jar -noCertificateCheck -s https://10.0.0.91/ groovy disableEnableJobsMatchingPattern.groovy jobPattern=build_git_auto disableOrEnable=disable --username 12345 --password banana

Reference
https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

 

 

Tagged : / / /

How to run/execute groovy script in Jenkins?

Here are the List of way using you can apply grovy code in Jenkins

Method -1: Groovy plugin
This plugin adds the ability to directly execute Groovy code.
More info – https://wiki.jenkins.io/display/JENKINS/Groovy+plugin

Method -2: Jenkins script console
The inbuilt script console is a very useful and powerful Jenkins extension and ideally suits certain types of tasks. This simple but powerful built-in web console allows you to run Groovy scripts on your Jenkins instance (or its slave nodes) from directly within the user interface, and is installed as standard.

To access the console, either navigate to Manage Jenkins and then select Script Console, or simply append /script to your Jenkins host and port, like this for example: http://jenkinshost:8080/script
Running Script Console on the master
This feature can be accessed from “Manage Jenkins” > “Script Console”. Or visit the sub-URL /script on your Jenkins instance.

Running Script Console on agents
Visit “Manage Jenkins” > “Manage Nodes”. Select any node to view the status page. In the menu on the left, a menu item is available to open a “Script Console” on that specific agent.

More info – https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

Method -3: Scriptler Plugins
Scriptler allows you to store/edit groovy scripts and execute it on any of the slaves/nodes… no need to copy/paste groovy code anymore.
More Info – https://wiki.jenkins.io/display/JENKINS/Scriptler+Plugin

Reference

https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

 

Tagged : / / / /

Database of Groovy Script for Jenkins Automation

Here are the list of Groovy Script which can be used in Jenkins to automate the JOBs and CI process. Please add your list in the comment sections as well.

Main Source – 

  • https://github.com/scmgalaxy/jenkins-groovy-script-example
  • https://github.com/cloudbees/jenkins-scripts
  • https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console
  • https://pghalliday.com/jenkins/groovy/sonar/chef/configuration/management/2014/09/21/some-useful-
  • jenkins-groovy-scripts.html
  • https://github.com/cloudbees/jenkins-scripts
  • https://github.com/jenkinsci/jenkins-scripts
  • https://gist.github.com/dnozay/e7afcf7a7dd8f73a4e05
  • https://github.com/samrocketman/jenkins-bootstrap-shared
  • https://github.com/samrocketman/jenkins-script-console-scripts

Example Groovy Script 

Tagged : /

Jenkins Architecture Explained!!!

Jenkins is continuous integration tools which help to integrate other tools to automate the software development activity and repetitive tasks. Jenkins has 2 releases. One, Community version which open source and free and another one is Jenkins Enterprise which is from Cloud bees for enterprise. Jenkins is extremely powerful with vast amount of plug-in supported. Jenkins is one of the most active open source projects so learning and finding the information is easily available on the internet. Jenkins uses master/slave architecture to manage distributed builds.
Jenkins Architecture

Jenkins Architecture is based on the distributed. This has 2 components.

  • Jenkins Server
  • Jenkins Node/Slave/Build Server

Jenkins server is a web dashboard which is nothing but powered from a war file, default run on 8080 ports. Using Dashboard, You can configure the Jobs/Projects but the build takes place in Nodes/Slave. By default one Nodes/Slave is configured and running in Jenkins Server. You can add more Nodes/Slave as well using IP address, user name, Password using the ssh/jnlp/webstart methods.

Your main Jenkins server is the master. In short, the master’s job is to handle scheduling build jobs, dispatching builds to the slaves for the actual execution, monitor the slaves (possibly taking them online and offline as required) and recording and presenting the build results. Even in a distributed architecture, a master instance of Jenkins can also execute build jobs directly.

The job of the slaves is to do as they are configured in the Jenkins Server, which involves executing build jobs dispatched by the master. You can configure a project to always run on a particular slave machine, or a particular type of slave machine, or simply let Jenkins pick the next available slave.
Jenkins is developed using Java and Java is platform independent thus Jenkins servers and nodes/slave can be configured in any servers including Windows, Linux and Mac.

Tagged : / / /

Difference between jenkins and Urbancode build

What is the difference between jenkins and Urbancode build?

jenkins Urbancode build
Jenkins is open framework for automating the repeative tasks and has great plugins which can be used to create entire automated customized continous integration framework. Urbancode build(uBuild) is for automating the repeative tasks and has great limited sets of plugins which can be used to create entire automated continous integration flow.
Jenkins can deliver core CI loop: Detect a change, do a build, test, and deliver feedback and its open framework allows and can be used for software Deployment as well. Urbancode build(uBuild) can deliver core CI loop: Detect a change, do a build, test, and deliver feedback but it can be not be used for deployment. Urbancode Deploy(uDeploy) is another product by IBM which can be used for deployment.
Jenkins can be extended with Large sets of plugins https://plugins.jenkins.io/ Urbancode build(uBuild) can be extended with Limited sets of plugins https://developer.ibm.com/urbancode/plugins/
Jenkins is one of top active Open Source and free developed in Java. Urbancode build(uBuild) is properiety tool by IBM, previously known as Urbancode and developed in Java
Jenkins has plugins which needs extra learning curve by development teams for centrally defined templates Urbancode build(uBuild) has built-in Easy addition of new projects by development teams based on centrally defined templates
Jenkins has Dependency management and but not awareness. Build based on project relationships. Urbancode build(uBuild) has Dependency management and awareness. Build based on project relationships.

My Recommendation – Jenkins

Tagged : / / / /

Build Scala Project using sbt and Jenkins

Build Scala Project using sbt and Jenkins

Agenda

  • Scala – A Scalable language
  • Scala Download
  • Scala Software Requirement
  • Scala IDEs
  • Scala Install Configuration
  • Scala First Program
  • Compile and Run
  • Building Scala Projects using Jenkins
  • Sbt downloand and configure
Tagged : / / / /

Does Jenkins let you create branches?

sathiya created the topic: Does Jenkins let you create branches?
All,

At my workplace we create weekly branches for releases. I tried p4 integ and p4 submit inside Jenkins so I could schedule branching. I used export to setup P4PORT and P4CLIENT. It dies saying files not in client view. Can you schedule Jenkins to create branches?

Thanks,
Rakhee

rajeshkumar replied the topic: Re: Does Jenkins let you create branches?
Hi,

At present perforce jenkins plugins just support following operations…
Polling
Synchronizing
Browsing latest changes
Labeling builds (tagging)
you can create your custom script to do so.However, the error which you are getting should be somthing related to your p4 client view. re-check your client view mapping and branch mapping. both should be in client view.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

/usr/bin/p4 error in windows machine with jenkins

rajeshkumar created the topic: /usr/bin/p4 error in windows machine with jenkins
Issues:

[workspace] $ “C:\Program Files\Perforce\p4.exe” login -p
[workspace] $ /usr/bin/p4 login -p

Solution:

This must be related to value of P4USER, P4PORT, P4PASSWD or P4TICKET variable is not getting passed to Jenkins.
Try following..
Restart Machine or Restart Services OR Set P4USER, P4PORT, P4PASSWD or P4TICKET and Restart Jenkins Services again.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

How to Change Jenkins HTTP port number?

scmuser created the topic: How to Change Jenkins HTTP port number?
How to Change Jenkins HTTP port number?

rajeshkumar replied the topic: How to Change Jenkins HTTP port number?
For Windows (service installation)
Edit jenkins.xml or hudson.xml

Navigate to the directory where you installed Jenkins/Hudson and you will see the XML at the root. Open it and look for tag, there will be all the command arguments to be used when starting up Jenkins or Hudson.
One of those arguments is –httpPort, typically:
–httpPort=8080.
Change 8080 to whatever port number you want.

WAR File, deployed in GlassFish
You will need to change the default HTTP port in GlassFish.

Natively installed in linux
At least for RHEL, you should be able to find the /etc/sysconfig/hudson, which typically has the following line, among other configuration ones:
HUDSON_PORT=”8080″.
Change 8080 to whatever port number you want.

Other linux distributions (using wrapper)
At the time of writing, Arch Linux’s AUR Jenkins version uses wrapper to launch itself from the .war file.

Edit /opt/jenkins/conf/wrapper.conf, find wrapper.app.parameter.2=–httpPort=8070 (typically).
Change 8070 to whatever port number you want.

This wrapper solution applies to any system using wrapper, not only linux.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :