Noam
Noam

Reputation: 1804

Jenkins: stop job at the middle from powershell

I have a Jenkins job which executes several powershell scripts, with the help of powershell plugin for jenkins (each script is in a different stage of the job).

In one of the stages there's an if condition, if this condition evaluates to true, I need to stop the job and mark it as success.

Here's the relevant part in the powershell script in the relevant stage:

# ....        
$is_after_restart = $content
    if ($is_after_restart -eq "true")
    {
        # Need to mark build as success and abort it.
    }

How can this be achieved?

Thanks.

Upvotes: 0

Views: 1214

Answers (2)

SV Madhava Reddy
SV Madhava Reddy

Reputation: 2018

If you are using multiple build steps, You can conditionally execute other build steps by using this plugin. Jenkins Conditional Branch Step Plugin.

If you just need to exit the current script and execute other scripts, please use this code.

$is_after_restart = $content
if ($is_after_restart -eq "true")
{
    exit 0
}

Upvotes: 1

Paxz
Paxz

Reputation: 3046

To stop the script and valudate the exitcode you can do something like this:

$is_after_restart = $content
if ($is_after_restart -eq "true")
{
    exit 0
}

0 is the standard exitcode for sucess. Although you can choose whatever exitcode you want to check in jenkins and replace the 0.

Upvotes: 1

Related Questions