Reference:
- Pipeline Syntax Reference : https://jenkins.io/doc/book/pipeline/syntax/
Note :
- Try catch block example in Pipeline syntax reference ( https://jenkins.io/doc/book/pipeline/syntax/ ) doesn't work.
Reference:
Note :
| stage('Stage Name') { | |
| steps { | |
| build(job: 'pipeline.name', parameters: [string(name: 'DEPLOY_TO', value: "test")]) | |
| } | |
| } |
| stage('Stage Name') { | |
| steps { | |
| build(job: 'Another Pipeline') | |
| } | |
| } |
| // Need to update the Themplate according to this documetation : https://jenkins.io/doc/book/pipeline/syntax/ | |
| pipeline { | |
| agent any | |
| environment { | |
| CC = 'clang' | |
| } | |
| stages { | |
| stage('Build') { | |
| steps { | |
| // | |
| } | |
| } | |
| stage('Test') { | |
| steps { | |
| // | |
| } | |
| } | |
| stage('Deploy') { | |
| steps { | |
| // | |
| } | |
| } | |
| } | |
| } |
| pipeline{ | |
| agent { | |
| label 'build.machine' | |
| } | |
| environment { | |
| GIT_URL = '[email protected]:rafaftahsin/Unity-Jenkinsfile-Exmaple.git' | |
| } | |
| stages{ | |
| stage('Try Catch Block'){ | |
| steps { | |
| script { | |
| try { | |
| sh ''' | |
| /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -runEditorTests "$(pwd)" -testFilter "$(pwd)/Library/ScriptAssemblies/Assembly-CSharp.dll" -editorTestsResultFile "$(pwd)/unit_test_result.xml" | |
| ''' | |
| } | |
| catch (exc) { | |
| sh 'cat unit_test_result.xml' | |
| error("Build Failed Due to Test Fail.") | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
| pipeline{ | |
| agent { | |
| label 'build.machine' | |
| } | |
| environment { | |
| GIT_URL = '[email protected]:rafaftahsin/Unity-Jenkinsfile-Exmaple.git' | |
| } | |
| stages{ | |
| stage('Git Clone'){ | |
| steps { | |
| deleteDir() | |
| slackSend channel: '#hal-alerts', message: "${env.JOB_NAME} is started" | |
| git branch: 'development', credentialsId: 'Jenkins Master SSH', url: "${GIT_URL}" | |
| } | |
| } | |
| } | |
| post { | |
| always { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME}" | |
| } | |
| } | |
| changed { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME} is CHANGED. See ${env.BUILD_URL} console for details." | |
| } | |
| } | |
| failure { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME} is FAILED. See ${env.BUILD_URL} console for details." | |
| } | |
| } | |
| success { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME} is SUCCESS. See ${env.BUILD_URL} console for details." | |
| } | |
| } | |
| unstable { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME} is UNSTABLE. See ${env.BUILD_URL} console for details." | |
| } | |
| } | |
| aborted { | |
| script{ | |
| slackSend channel: '#channel-name', message: "${env.JOB_NAME} is ABORTED. See ${env.BUILD_URL} console for details." | |
| } | |
| } | |
| } | |
| } |
| node ('nodename'){ | |
| stage('Build') { | |
| // | |
| } | |
| stage('Test') { | |
| // | |
| } | |
| stage('Deploy') { | |
| // | |
| } | |
| } |