CircleCI-Public / slack-orb

Create custom Slack notifications for CircleCI job statuses
https://circleci.com/developer/orbs/orb/circleci/slack
MIT License
213 stars 205 forks source link

Include custom variables in slack message #76

Closed alan-parry closed 5 years ago

alan-parry commented 5 years ago

Orb version

3.3.0

What happened

I'm trying to include custom variables which are established earlier in my build in the slack message. To pass these between previous steps I do

echo "export GIT_COMMIT_MESSAGE=$GIT_COMMIT_MESSAGE" >> variables/var.sh

then for steps where I require these I first do:

source ~/work/variables/var.sh

This works fine but I don't see a way to bring these in to my slack orb steps. Is there a fix or a workaround you can suggest? Thanks!

Expected behavior

My message should include the variable values, instead they are blank.

alan-parry commented 5 years ago

I resolved this by adding variables to the BASH_ENV

emmahsax commented 4 years ago

Can you post the final code that you used to add the values to the $BASH_ENV?

iamtgray commented 4 years ago

Also want to know how to do this if possible? @alan-parry

emmahsax commented 4 years ago

@iamtgray I ended up finding this solution: https://github.com/emmasax4/emmasax4.info/blob/ca5737d4c9de55f2a0947143a011e1b42a29968a/.circleci/generate-slack-message.sh#L17-L18 https://github.com/emmasax4/emmasax4.info/blob/ca5737d4c9de55f2a0947143a011e1b42a29968a/.circleci/config.yml#L45-L46

So this works nicely.

victorboissiere commented 4 years ago

The URLs are not working anymore. I used something like this:

echo "export BUILD_OUTPUT_MESSAGE='My custom variable to use in Slack orbs'" >> $BASH_ENV
emmahsax commented 4 years ago

@victorboissiere I've updated the URLs in the comment above. Sorry about that. I try not to link to things directly on a branch, but rather on a SHA commit so the URLs persist, but I guess I got lazy on this one.

NenadJovicic commented 4 years ago

Still don't see how to include actual commit message, and not SHA of commit because it is useful to see actual commit message. No one knows commit SHA :smile:

KyleTryon commented 4 years ago

@NenadJovicic Here's a cheat to get the commit message:

echo "export COMMIT_MESSAGE=\"$(git log --format=oneline -n 1 $CIRCLE_SHA1)\"" >> $BASH_ENV

source: https://discuss.circleci.com/t/git-commit-message-in-environment-variable/533/13

NenadJovicic commented 4 years ago

@KyleTryon yup, found it exactly there after asking question here :smile: thanks