hello,

I have the slack <https://plugins.jenkins.io/slack> & job-dsl 
<https://plugins.jenkins.io/job-dsl> plugins installed & configured in my 
jenkins instance.

I run the seed job for the following my-slack.groovy file:

job("myfolder/myjob") {
  steps {
      shell("""#!/bin/bash
      echo "hello"
      """)
  }

  publishers {
    // See 
https://issues.jenkins-ci.org/browse/JENKINS-34124?focusedCommentId=253825 
for an e.g. of how to call 'slackNotifier'. And the
    // source code is at: 
https://github.com/jenkinsci/slack-plugin/blob/slack-2.3/src/main/java/jenkins/plugins/slack/SlackNotifier.java
    slackNotifier {
      room('#jenkins')

      notifySuccess(true)

      includeCustomMessage(true)
      String buildURL = System.getenv("BUILD_URL")
      String otherBuildURL = "\$BUILD_URL"
      customMessage("BUILD_URL=\$BUILD_URL buildURL={$buildURL} 
otherBuildURL=${otherBuildURL}")
    }
  } // publishers
} // job


(Note that BUILD_URL is listed on the jenkins Available Environment 
Variables <https://jenkins.pearsonvue.com/env-vars.html/> page.)

When I run the job, the notification I receive in my Slack channel has the 
following text: 

BUILD_URL=http://jenkins-ui:8080/job/myfolder/job/myjob/12/ buildURL=*null*
 otherBuildURL=*http://jenkins-ui:8080/job/myfolder/job/myjob/12/*


But what I would like to do is (when myjob is run - not when the seed job 
is run) be able to get a copy of BUILD_URL and edit the copy and include 
that in customMessage. Is there any way to do that? (e.g. perhaps with the 
Scriptler 
Plugin <https://wiki.jenkins.io/display/JENKINS/Scriptler+Plugin>?)

e.g. when I add the following code to my-slack.groovy (right after the line 
where otherBuildURL is initially declared):

otherBuildURL += "console"

then I get this in the Slack notification:

otherBuildURL=*$BUILD_URLconsole*


To sum this up: what I'm going for is whenever myjob is run, I would like 
the Slack notification text to include a link to the console output - e.g.: 

http://jenkins-ui:8080/job/myfolder/job/myjob/12/*console*


(Please let me know if I should instead direct this post somewhere else - 
e.g. the job-dsl-plugin 
<https://groups.google.com/forum/#!forum/job-dsl-plugin> group.)

Any suggestions would be greatly appreciated. thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/36fec760-d673-4b70-876b-c9b9ceb744f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to