jenkinsci / hipchat-plugin

HipChat notification plugin for Jenkins
https://plugins.jenkins.io/hipchat/
54 stars 85 forks source link

token vs custom variable expansion in message #118

Closed joeypiccola closed 5 years ago

joeypiccola commented 6 years ago

I am having issues getting both a token-macro and custom variable to appear in a HipChat message. I can get what I want with double quotes but then the token-macro breaks. Below is my Jenkinsfile with a few examples showing various outputs (shown in the comment below each hipchatsend). Sorry for all the examples, I just wanted to document what works and when as I am unsure of the expected behavior.

Thanks for the help, Joey

def buildspecParam = readJSON text: "${env.buildspec}"
def buildDesc = "${buildspecParam.datacenter}\\${buildspecParam.cluster}\\${buildspecParam.vmname}"
def myvalue = 'whateverIwant'
pipeline {
    agent any
    environment {
        test = 'asdf'
        datacenter = "${buildspecParam.datacenter}"
    }
    stages {
        stage('set build data') {
            steps {
                hipchatSend message: '$BUILD_DURATION', room: 'isg-server-deploy-test',  textFormat: true
                // 0.45 sec
                hipchatSend message: "${BUILD_NUMBER}", room: 'isg-server-deploy-test',  textFormat: true
                // 106
                hipchatSend message: "${datacenter} - ${test} - ${myvalue}", room: 'isg-server-deploy-test',  textFormat: true
                // DEN3 - asdf - whateverIwant
                hipchatSend message: '$BUILD_DURATION - $BUILD_NUMBER', room: 'isg-server-deploy-test',  textFormat: true
                // 1 sec - 106
                hipchatSend message: '$BUILD_DURATION - $BUILD_NUMBER - $test - $myvalue', room: 'isg-server-deploy-test',  textFormat: true
                // 1 sec - 106 - $test - $myvalue
                hipchatSend message: "x - $BUILD_NUMBER - $test - $myvalue", room: 'isg-server-deploy-test',  textFormat: true
                // x - 107 - asdf - whateverIwant
                hipchatSend message: "${BUILD_DURATION} - $BUILD_NUMBER - $test - $myvalue", room: 'isg-server-deploy-test',  textFormat: true
                // groovy.lang.MissingPropertyException: No such property: BUILD_DURATION for class: WorkflowScript
                hipchatSend message: "$BUILD_DURATION - $BUILD_NUMBER - $test - $myvalue", room: 'isg-server-deploy-test',  textFormat: true
                // groovy.lang.MissingPropertyException: No such property: BUILD_DURATION for class: WorkflowScript
                script {
                    currentBuild.description = "${buildDesc}"
                }
            }
        }
    }
}
rfrister commented 6 years ago

Hi Joey, (just in case this is still an issue)

you can concatenate strings to make this work.

Like

hipchatSend message: '$BUILD_DURATION - ' + myvalue, room: 'isg-server-deploy-test', textFormat: true