I’m trying to extract the user who is triggered the Jenkins job and testNG execution status from Jenkins console.
Need to get below details from Jenkins console using Linux command.
Jenkins console log:
Started by user achuMohan
===============================================
TransferMoneyTest
Tests run: 10, Pass: 5 Failures: 3, Skips: 2
===============================================
Output:
achuMohan Run:10 Pass:5 Failures:3 Skips: 2
I tried the below command to get all the console logs but not sure how can I proceed further.
userName=$(curl -u 'user:password' --silent "https://hostname/Dev-CI-MILLENIUM-1924/job/Test_Kindle/$BUILD_NUMBER/logText/progressiveText?start=0") Pass=$(curl -u 'user:password' --silent "https://hostname/Dev-CI-MILLENIUM-1924/job/Test_Kindle/$BUILD_NUMBER/logText/progressiveText?start=0") Fail=$(curl -u 'user:password' --silent "https://hostname/Dev-CI-MILLENIUM-1924/job/Test_Kindle/$BUILD_NUMBER/logText/progressiveText?start=0") skip=$(curl -u 'user:password' --silent "https://hostname/Dev-CI-MILLENIUM-1924/job/Test_Kindle/$BUILD_NUMBER/logText/progressiveText?start=0")
I want to fetch the above output and store it into the variable as like above.
Is it possible to extract only above things from the entire console log by using linux command else anyother way to achieve?
Advertisement
Answer
You can use below command to get the test result data :
curl -u 'user:password' --silent "${JENKINS_URL}/job/${JOB_NAME}/lastBuild/consoleText"| grep "^Tests"| sed "s/Tests //g"| awk -F", " '{ print $1"n"$2"n"$3}'
The output of the above command will be :
run: 10 Pass: 5 Failures: 3
For username you can use below command :
curl -u 'user:password' --silent "${JENKINS_URL}/job/${JOB_NAME}/lastBuild/consoleText" | awk '/Started/{print $NF}'
This will give output as :
achuMohan
You can put these data into a file and then use cat
to print it on terminal.