Deployment can imply a variety of steps, depending on the project or organization requirements, and may be anything from publishing built artifacts to an Artifactory server, to pushing code to a production system.
At this stage of the example Pipeline, both the "Build" and "Test" stages have successfully executed. In essence, the "Deploy" stage will only execute assuming previous stages completed successfully, otherwise the Pipeline would have exited early.
pipeline { agent any stages { stage('Deploy') { when { expression { currentBuild.result == null || currentBuild.resukt == 'SUCCESS' (1) } steps { sh 'make publish' } } } } }
1 | Accessing the currentBuild.result variable allows the Pipeline to
determine if there were any test failures. In which case, the value would be
UNSTABLE . |
node { /* .. snip .. */ stage('Deploy') { if (currentBuild.result == null || currentBuild.result == 'SUCCESS') { (1) sh 'make publish' } } /* .. snip .. */ }
1 | Accessing the currentBuild.result variable allows the Pipeline to
determine if there were any test failures. In which case, the value would be
UNSTABLE . |
Assuming everything has executed successfully in the example Jenkins Pipeline, each successful Pipeline run will have associated build artifacts archived, test results reported upon and the full console output all in Jenkins.
A Scripted Pipeline can include conditional tests (shown above), loops, try/catch/finally blocks and even functions. The next section will cover this advanced Scripted Pipeline syntax in more detail.