I have a declarative Jenkins pipeline. I want to have a conditional in the "post" section of a build.
Is it possible to have "script blocks" in the post section of a jenkins file?
When I put it like this, no errors occur, but no hipchat messages are sent. Even if say "if master branch, hipchatSend, else hipchatSend", no hipchat messages are sent. Heck, if I replace hipchatSend with "echo" statements, nothing happens either.
post {
always {
script {
if (env.BRANCH_NAME == "master") {
hipchatSend color: 'RED', credentialId: 'HipChat-Jenkins-Token',
message: 'I am master branch',
room: 'Master-Commit-Room,',
sendAs: '',
server: '',
v2enabled: true
}
if (env.BRANCH_NAME == "release/my-release") {
hipchatSend color: 'RED', credentialId: 'HipChat-Jenkins-Token',
message: 'I am release branch',
room: 'Release-Commit-Room,',
sendAs: '',
server: '',
v2enabled: true
}
}
}
}