I am building a pipeline job in jenkins in groovy, and it has to run a batch command first, upon s - windows

I have to build a jenkins pipeline job using groovy script, what the job has to do is, first run an windows batch command, and only if the batch command build is successful, it should call build for another job. How can I find out is the windows batch command was build successfully. I am showing sample code for the query.
import groovy.json.JsonSlurper;
import hudson.model.*
import hudson.EnvVars
pipeline {
agent any
stages {
stage('Build')
{
steps{
bat 'some batch command here'
// if(bat build successful)---> need help here
build 'xyz' //xyz is another job that I am calling here
}
}
}

This is the default behavior of steps: if one of the step fails, it stops.
That bat step includes:
Normally, a script which exits with a nonzero status code will cause the step to fail with an exception
If your batch command does fail, its errorlevel should be different of 0, which is enough to make the steps chain fail.

Related

bash: stop subshell script marked as failed if one step exits with an error

I am running a script through the SLURM job scheduler on HPC.
I am invoking a subshell script through a master script.
The subshell script contains several steps. One step in the script sometimes fails because of the quality of the data; this step is not required for further steps, but if this step fails, my whole subshell script is marked with "failed" Status in the job scheduler. However, I need this subshell script to have a "completed" Status in the Job scheduler as it is dependency in my master script.
I tried setting up
set +e
in my subshell script right before the optional step, but it doesn't seem to work: I still get an exitCode with errors and FAILED status inthe job scheduler.
In short: I need the subshell script to have Status "completed" in the job scheduler, no matter whether one particular step is finished with errors or not. Will appreciate help with this.
For Slurm jobs submitted with sbatch, the job exit code is taken to be the return code of the submission script itself. The return code of a Bash script is that of the last command in the script.
So if you just end your script with exit 0, Slurm should consider it COMPLETED no matter what.

Unable to run a windows task that makes https request under SYSTEM account

I have created a windows cmd file that calls three independent bat files. I want to create a windows task that calls this cmd file and runs every 5 minutes. The problem is that this task runs perfectly fine only when I'm logged into the system. But I'm unable to make this task continue to run "whether I'm logged in or not".
I even asked my colleague to login to that machine and run this task under his account - it worked. I created a local admin user on that machine, logged in as that user, tried to run this task - it did not work - the script waits forever while post_results.bat. I even tried to schedule a jenkins job that basically does the same thing - it did not work - the jenkins job waits forever while post_results.bat (I killed the jenkins job after waiting for ~20 min).
Here is a summary of what these tasks are doing:
run_all.cmd
call "run_test.bat"
call "post_results.bat"
call "clean.bat"
run_test.bat - executes a jmeter script
C:\Users\Administrator\LS2\apache-jmeter-4.0\bin\jmeter -n -t api_strategy_synthetic_tests.jmx -JTestEnv=amer1 -l Result_log.jtl
post_results.bat - calls a python script that posts the jmeter test results to datadog
python post_jmeter_results_to_datadog.py Result_log.jtl
post_jmeter_results_to_datadog.py - uses the datadog python api to post metrics to datadog
#!/usr/bin/env python3
import sys
import pandas as pd
from datadog import initialize, api
options = {
'api_key': <API_KEY>,
'app_key': <APPLICATION_KEY>
}
initialize(**options)
jtl_file = sys.argv[1]
df = pd.read_csv(jtl_file)
for index, row in df.iterrows():
tag = "success:" + str(row['success'])
api.Metric.send(
metric=row['label'],
points=[(row['timeStamp']/1000,row['elapsed'])],
tags=[tag]
)
clean.bat - deletes the jmeter test result files
rmdir /s /q "errors"
del "jmeter.log"
del "Result_log.jtl"
All I need is to be able to run this task every 5 minutes. If anyone is able to see what I'm doing wrong and points that out... I'd be really grateful.
You can create one PowerShell script to execute your Batch scripts remotely.
And Even you can schedule your PowerShell script using Windows Task Scheduler which will run as per your settings.

Running shell script from jenkins

When i try to execute the jobs from terminal it works for one hour without any issue. when i try to execute shell from Jenkins it works for just one minute and stops the execution. The output from Jenkins console output as follows :
Creating folder path in /jenkins/workspace/load_test/scripts/loadtest/loadtest1
PWD is : /jenkins/workspace/load_test/scripts/loadtest
Running /jenkins/workspace/load_test/scripts/loadtest/loadtest1/testRestApi.sh
1495126268
1495129868
3600
Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
Finished: SUCCESS
Any ideas/ suggestion to make the script run for one hour from Jenkins job ?
Have you tried with BUILD_ID=dontKillMe it is commonly used for daemons. https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller however this should let you run your script

Autosys job not failing when the shell script fails

I am moving existing manual shell scripts to execute via autosys jobs. However, after adding exit 1 for each failed autosys job; it is not failing and autosys shows exit code as 0.
I tried the below simple script
#!/bin/ksh
exit 1;
When I execute this, the autosys job shows a success status.I have not updated success code or max success code in autosys, everything is default. What am I missing?

Jenkins trigger conditional build steps in shell?

I am using Jenkins as a server to run cron jobs that are conditional on the success of other jobs. These can be run as multiple execute shell steps. I am specifically wondering if there is a way to make an execute shell step contingent on the exit status of the previous execute shell step.
This is the default behaviour. Each build step, such as "Execute Shell" step, returns an exit code (last command). If that is 0, the next build step is executed. If that is not 0, Jenkins "FAILS" the build, and skips straight to post-build steps.
If your shell returns 0 on success, and everything else is a failure, just put several "Execute Shell" build steps one after another.

Resources