jenkinsci / hipchat-plugin

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

Cannot use ${BUILD_DURATION} ? #124

Open igloocube opened 6 years ago

igloocube commented 6 years ago
pipeline {
  agent any

  stages {

    stage('dummy') {

      steps {
        sh returnStatus: true, script: 'date'
      }

    }
  }

  post {

    always {

      hipchatSend (
        color: 'GRAY',
        failOnError:
        false,
        message: "Duration: ${BUILD_DURATION}",
        notify: true,
        textFormat: false
      )

    }

  }

}

Results in: groovy.lang.MissingPropertyException: No such property: BUILD_DURATION for class: groovy.lang.Binding

igloocube commented 6 years ago

Ok so message: 'Duration: ${BUILD_DURATION}', with single quotes works but not with env variables though.

How can you combine the 2? I've tried this for example:

message: 'Duration: ${BUILD_DURATION} ${env.CHANGE_AUTHOR} $env.CHANGE_AUTHOR'

Prints:

Duration: 4 sec ${env.CHANGE_AUTHOR} $env.CHANGE_AUTHOR

igloocube commented 6 years ago

I've found you can join/concatenate like so, is there no better way?

message: 'Duration: ${BUILD_DURATION}' + " Display name: ${env.BUILD_DISPLAY_NAME}",
seboudry commented 6 years ago

Hi, put mine too (ENV and TAGS are build parameters):

message = 'Succeeded <a href="${BLUE_OCEAN_URL}">#${BUILD_NUMBER}</a> - ' +
    "Deployment on <b>${ENV.toUpperCase()}</b> environment with tags <b>${TAGS ?: 'none'}</b></br>" +
    'Time elapsed: ${BUILD_DURATION}. Check the <a href="${BUILD_URL}/console">console output'

Then I use this string variable in hipchatSend.