Posts

Showing posts with the label Jenkins

Create HTML dashboard of Jenkins jobs status

Image
Perl script to fetch live jobs' status from Jenkins server and generate and display HTML dashboard from it. use strict; use warnings; use autodie; use REST::Client; use MIME::Base64; use JSON; my $api_proto = 'http';               #HTTP/HTTPS my $api_url = 'localhost';       #Server IP my $api_port = '8080';                #Port number my $api_user = 'admin';           #Jenkins account username my $api_pass = 'password';          #Jenkins account password my $client = REST::Client->new();    #Perl Rest Client Object $client->addHeader('Authorization', 'Basic '.encode_base64($api_user . ':' . $api_pass)); $client->GET($api_proto.'://'.$api_url.':'.$api_port.'/api/json?tree=jobs[name,color,url]'); my $html = ""; $html = $ht...

Build Jenkins Job Remotely | Fix: Error 403 No valid crumb was included in the request

Image
In case you are a newbie with Jenkins read through this article: http://com.puter.tips/2017/09/getting-up-and-running-with-jenkins.html Build Jenkins Job Remotely I have found two ways in which you can trigger a build on job remotely via scripting. Both methods are simple HTTP Get/Post requests, nothing fancy here. Along with these Requests we need to pass login credentials. Method 0: No protection enabled => This is the case when you are in a secure environment and have disabled all additional protection mechanism like CSRF (Method 1) and Authentication Token (Method 2). If this is the case then you can simply trigger a HTTP Request like this: 'http://username:password@jenkins_url:port/job/job_name/build' e.g. http://admin:pass@localhost:8080/job/job1/build

Jenkins: Trigger build remotely via script using Authentication Token

Image
Powershell: $acctname = "admin" $password = "password" $server = "localhost" $port = "8080" $jobName = "test02" $jobToken = "test02_authentication_token" $params = @{uri = "http://${server}:${port}/job/${jobName}/build?token=${jobToken}";             Method = 'Get';             Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${acctname}):$(${password})"));}} Invoke-RestMethod @params

Jenkins: Trigger build remotely via script using crumb

Image
Python: import requests api_proto = 'http' api_url = 'localhost' api_port = '8080' api_job = 'test01' api_user = 'admin' api_pass = 'password' api_crumb = requests.get(api_proto + '://' + api_user + ':' + api_pass + '@' + api_url + ':' + api_port + '/crumbIssuer/api/json') if api_crumb.status_code == 200 :     api_crumb = api_crumb.json()['crumb'] resp = requests.post(api_proto + '://' + api_url + ':' + api_port + '/job/' + api_job + '/build', auth=(api_user, api_pass), headers={"Jenkins-Crumb":api_crumb}) if resp.status_code == 201:     print(api_job + ' was triggered successfuly..')

Getting up and running with Jenkins 2.60.3 on Windows [How to solve Error: no workspace]

Image
Jenkins: The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project. Jenkins is a Continuous Integration server. Basically Continuous Integration is the practice of running your tests on a non-developer machine automatically every-time someone pushes new code into the source repository. Prerequisites: Java Development Kit (JDK) Java Run-time Environment (JRE) To install JDK go to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html To install JRE go to http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html