Jenkins V2

Jenkins V2 - IT automation and coordination updates

We want to develop CD solutions and are looking at Bamboo amongst others. But Jenkins V2 is freely available and does have the advantage of working with all our legacy techniques and scripts, including the huge range of plugins available for many different products. This page is new and will be built as techniques come into my repertoire.

First thing I need to do, due to legacy growth, is get my old Jenkins jobs working from where they are, but controlled form my new installation. This is mainly because the legacy setup has a lot of techniques, scripts and variables that no longer have full coverage and support. So my first V2 script actually just runs the old jobs, checks on theri progress and pass/fail values and reports back the answers to tmy current V2 installation. In fact, this technique is really useful and saves a lot of time on re-writing legacy approaches.

I�m going to provide my Jenkins script here in full but of course, you may need to update it for your purposes. What ti does, is run a Jenkins job at a distance, then check on the runtime status and when the job had finished, report back the same result to our current Jenkins, either pass or Fail:

Run a SIMPLE Jenkins job from a distance
(I need to develop a second script for posting variables down, see below)

I have had to edit the URLs for our own internal security:

    jenkins_job=${external_jenkins_job}
    echo ------------ running ${jenkins_job} on server-deploy01 --------------

    passmark=0
    START=1
    END=60
    echo start = $START
    echo end = $END

    ###notes: http://server-deploy01/jenkins/view/perf-ci/job/all4web_perf_status/build?delay=0sec

    wget --no-cookies --header "Cookie: screenResolution=1920x1080; JSESSIONID.3359c4fb=907de103b571....d6355e68850bc; JSESSIONID.9c30b717=80ad4fa2c....9bfa93a74b6aa8be;
     screenResolution=1920x1080; ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=bmdvZGZyZXk6MT...
    ..jQ1NjEwMjo4ZDA5OTUxYTUyOWI4MWE0ZjhkOTI5MTRlMTMwZGRiNQ=="
    http://server
    -deploy01/jenkins/view/perf-ci/job/${jenkins_job}/build?delay=0sec

    ## save $START, just in case if we need it later ##
       i=$START
       while [[ $i -le $END ]]
       do
           echo "$i"
                
               sleep 60
               wget --no-cookies --header "Cookie: screenResolution=1920x1080; JSESSIONID
    .3359c4fb=907de103b571....d6355e68850bc; JSESSIONID.9c30b717=80ad4fa2c....9bfa93a74b6aa8be;
    screenResolution=1920x1080; ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=bmdvZGZyZXk6MT....
    .jQ1NjEwMjo4ZDA5OTUxYTUyOWI4MWE0ZjhkOTI5MTRlMTMwZGRiNQ=="
    http://server
    -deploy01/jenkins/view/All/ -O all.html

               R_num=$(grep ${jenkins_job} all.html | awk 'BEGIN {FS="tooltip=\""} {print $2}' | head -1 |
     awk 'BEGIN {FS="\""} {print $1}')
               echo $R_num

               if [ "${R_num}" == "Failed" ]  || [ "${R_num}" == "Aborted" ] || [ "${R_num}" == "Success" ]; then
                     #Finished
                     if [ "${R_num}" == "Failed" ] || [ "${R_num}" == "Aborted" ] ; then
                           echo last job failed. exiting failure
                           passmark=1
                           break
                     else
                           echo last job PASSED. exiting PASS
                           passmark=0
                           break
                     fi
               else
                     echo job still running
                     sleep 60
               fi
              
               ((i = i + 1))
              
       done
                  
       exit ${passmark}
      

 

With more complex Jenkins jobs (that we typically have here for deploying environments etc.) we need something a bit more complex. In particular we need to POST the variables data down to jenkins and still have the cookies etc. for login credentials etc.

So here is a more complicated script. Now, in fact, it�s not really hard to develop your own version of this. Just build your job by hand and use Fiddler to trace the requests. Then the details can be put in the wget command, just noting the cookie separately from the POST data:

Run a COMPLEX Jenkins job from a distance

I have had to edit the URLs for our own internal security:

    jenkins_job=${external_jenkins_job} #=Deploy-xxxxxxxxxxx-to-perf
    echo ------------ running ${jenkins_job} on server-deploy01 --------------

    passmark=0
    START=1
    END=120
    echo start = $START
    echo end = $END

    echo --- using Fiddler trace of fixed job request ---

    wget --no-cookies --header "Cookie: JSESSIONID.3359c4fb=907de103b57........1d6355e68850bc;
     ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=bmdvZGZyZXk6MTQ3NDY0MjQ1NjEw.........
    .xYTUyOWI4MWE0ZjhkOTI5MTRlMTMwZGRiNQ==; JSESSIONID.9c30b717=636b872a......
    .22d89acc3db4d54; screenResolution=1920x1080" --post-data 'name=versionToDeploy&value=0.1
    -SNAPSHOT&name=useNextFarmGenerationNumber&value=
    -N&name=useLatestFarmGenerationNumber&value=+&name=prePromote&value=yes&name=autoPromote
    &value=yes&name=applicationName&value=xxxxxxxxxxx&name=targetEnvironment&value=perf&name=far
    mGenerationNumber&value=&json=%7B%22parameter%22%3A+%5B%7B%22name%22%3A+
    %22versionToDeploy%22%2C+%22value%22%3A+%220.1-SNAPSHOT%22%7D%2C+%7B%22name%22
    %3A+%22useNextFarmGenerationNumber%22%2C+%22value%22%3A+%22-N%22%7D%2C+%7B
    %22name%22%3A+%22useLatestFarmGenerationNumber%22%2C+%22value%22%3A+%22+%22%7D
    %2C+%7B%22name%22%3A+%22prePromote%22%2C+%22value%22%3A+%22yes%22%7D%2C+%7B
    %22name%22%3A+%22autoPromote%22%2C+%22value%22%3A+%22yes%22%7D%2C+%7B%22name
    %22%3A+%22applicationName%22%2C+%22value%22%3A+%22xxxxxxxxxxx%22%7D%2C+%7B
    %22name%22%3A+%22targetEnvironment%22%2C+%22value%22%3A+%22xxxx7D%2C+%7B%22name
    %22%3A+%22farmGenerationNumber%22%2C+%22value%22%3A+%22%22%7D%5D%7D&Submit=Build'
    http://server-deploy01/jenkins/job/${jenkins_job}/build?delay=0sec


       i=$START
       while [[ $i -le $END ]]
       do
           echo "$i"
                
               sleep 60
               wget --no-cookies --header "Cookie: screenResolution=1920x1080; JSESSIONID
    .3359c4fb=907de...........feba1d6355e68850bc; JSESSIONID.9c30b717=80ad4fa........
    .0869bfa93a74b6aa8be; screenResolution=1920x1080;
    ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=bmdvZGZyZXk6MTQ3NDY0Mj...........
    .TUxYTUyOWI4MWE0ZjhkOTI5MTRlMTMwZGRiNQ==" http://server-deploy01/jenkins/view/All/ -O all.html

               R_num=$(grep ${jenkins_job} all.html | awk 'BEGIN {FS="tooltip=\""} {print $2}' | head -1 |
     awk 'BEGIN {FS="\""} {print $1}')
               echo $R_num

               if [ "${R_num}" == "Failed" ]  || [ "${R_num}" == "Aborted" ] || [ "${R_num}" == "Success" ];
     then
                     #Finished
                     if [ "${R_num}" == "Failed" ] || [ "${R_num}" == "Aborted" ] ; then
                           echo last job failed. exiting failure
                           passmark=1
                   break
                     else
                           echo last job PASSED. exiting PASS
                           passmark=0
                   break
                     fi
               else
                     echo job still running
                     sleep 60
               fi
              
               ((i = i + 1))
              
       done
                  
       exit ${passmark}
      
      

 

Call web services to set DB levels and check results

[note, using �|| true� to avoid wget response codes from breaking the script flow]
[using �grep -n� to return line numbers]
[using �((end = start + 15))� to set numeric values of variables with maths]
[using �sed -n "${start},${end}p" info.html > check� to grab certain file lines to a local log]

    ####!/bin/bash (in my Jenkins V2 cygwin bash isn�t being picked up properly)
    passmark=0

    #high:
    #p.user_datalist-perf 2,000 - 3,000
    #p.user_history-perf 1,500 - 2,000
    #p.user_playlist-perf 600 - 1,000

    #low all: read: 400, write: 100

    read_s=2000
    read_c=2,000
    write_s=3000
    write_c=3,000
    table_s=p.user_datalist-perf

    wget --save-headers http://user-v1.core.website.com/admin/_internal/dynamo/capacity --post-data "read=${read_s}&write=${write_s}&tableName=${table_s}" -O set.html || true
    echo wait a while before checking new settings
    sleep 30

    echo check dynamoDB setting:
    wget --save-headers http://user-v1.core.perf.website.com/admin/_internal/dynamo/info -O info.html || true

    echo Find correct area of data file
    start=$(grep -n "${table_s}" info.html | head -1 | awk 'BEGIN {FS=":"} {print $1}')
    echo $start
    ((end = start + 15))
    sed -n "${start},${end}p" info.html > check
    echo show results on screen
    cat check

    echo look for correct read values
    grep -q "<td>${read_c}</td>" check
    r1=$?
    echo grep result is $r1
    if [ "$r1" -ne "1" ] ; then
               echo "read returned ok"
    else
               echo "error on read check"
           passmark=1
    fi

    echo look for correct write values
    grep -q "<td>${write_c}</td>" check
    w1=$?
    echo grep result is $w1
    if [ "$w1" -ne "1" ] ; then
               echo "write returned ok"
    else
               echo "error on write check"
           passmark=1
    fi

    exit $passmark

 

 

 

 

[Home] [About (CV)] [Contact Us] [JMeter Cloud] [webPageTest] [_64 images] [asset moniitor] [Linux Monitor] [Splunk ETL] [Splunk API] [AWS bash] [LR Rules OK] [LR Slave] [LR CI Graphs] [LoadRunner CI] [LR CI Variables] [LR Bamboo] [LR Methods] [LR CI BASH] [Bash methods] [Jenkins V2] [J V2 Pipeline1] [Jv2 Jobs] [Jv2 Analysis] [Jv2 Analysis2] [Streaming vid] [How fast] [Finding Issues] [Reporting] [Hand over] [VB Scripts] [JMeter tips] [JMeter RAW] [Dynatrace] [Documents] [FAQ] [Legal]

In the Cartesian Elements Ltd group of companies