Reputation: 671
I want to send slack message after Jenkins build a task like this:
My_Job - #10 Success after 18 sec (Open)
My Report: http://my_domain/report_20181017195500.html
So I tried to set this varialbe in the Execute shell
area of the job in Jenkins:
...
DATE=`date '+%Y%m%d%H%M%S'`
MY_REPORT="report-$DATE.html"
Add this to the Include Custom Message
of the Slack Notifications
block:
My Report: http://my_domain/${MY_REPORT}
But when I check the Slack channel, it send me:
My_Job - #10 Success after 18 sec (Open)
My Report: http://my_domain/${MY_REPORT}
How to set $MY_REPORT
the true value in this case?
I have tried EnvInject
plugin. Set this code to the Execute shell
block:
...
echo MY_REPORT=$(echo "http://my_domain/report-$DATE.html") > /var/lib/jenkins/var.properties
It can read value from the /var/lib/jenkins/var.properties
which set in the Inject environment variables to the build process
of Build Environment
block. But can't write into that file from Execute shell
.
Upvotes: 6
Views: 8702
Reputation: 11
After some trial and error I found that I needed to:
Upvotes: 0
Reputation: 14575
Environment variables are acessible for building custom slack notifications. In my case I'm using variables from GitLab webhooks configured to trigger builds to customize slack messages:
So this message definition:
Results in this slack notification:
Upvotes: 1
Reputation: 142
You can do this:
slackSend channel: 'channel_name', message: 'My_Job - ' + BUILD_NUMBER + '\nMy_Report:' + JENKINS_URL
Upvotes: 1