<p>The scripted equivalent to the declarative</p>
<pre><code>steps {
  // pipeline steps here
post {
  failure {
    // failure handler here
  }
  success {
    // success handler here
  }
  always {
    // always handler here
  }
}
</code></pre>
<p>is the native Groovy <code>try { } catch { }</code>:</p>
<pre><code>try {
  // pipeline steps here

  // success handler here
} catch(Exception e) {
  // failure handler here
} finally {
  // always handler here
}
</code></pre>
<p>I'm not sure off the top of my head how to add an abort handler, but I think you might be able to do it by inspecting the <code>currentBuild.result</code> variable in the failure handler block.</p>

CC BY-SA 4.0
2020-09-02T16:56:54.727Z
2020-09-02T16:56:54.727Z
jayhendren
<p>I already used the following declarative script as a part of my cleanup script, now I should convert it to the scripted pipeline, how I can convert the post to the scripted pipeline?</p>

<jenkins>
convert declarative pipeline to scripted pipeline
Mkash
# convert declarative pipeline to scripted pipeline

(Asked by: username_0 on 2020-09-02)

I already used the following declarative script as a part of my cleanup script, now I should convert it to the scripted pipeline, how I can convert the post to the scripted pipeline?

**Tags:** jenkins


---

## 1 answers

### Answer by username_1 on 2020-09-02. Score: 2 | Accepted answer

The scripted equivalent to the declarative
steps {
  // pipeline steps here
post {
  failure {
    // failure handler here
  }
  success {
    // success handler here
  }
  always {
    // always handler here
  }
}

is the native Groovy try { } catch { }:
try {
  // pipeline steps here

  // success handler here
} catch(Exception e) {
  // failure handler here
} finally {
  // always handler here
}

I'm not sure off the top of my head how to add an abort handler, but I think you might be able to do it by inspecting the currentBuild.result variable in the failure handler block.


---

