Closed jku-sr closed 2 years ago
Hey @jku-sr 👋🏻 Thanks for the question!
You can use environment variables to set the channel-id
parameter, but we don't have a first-class CHANNEL_ID
environment variable. Here's a Stack Overflow article that explains how to access environment variables as parameter values.
Your implementation may look something like this using the environment variable CHANNEL_ID
:
- name: Post to Slack
id: slackinitial
uses: slackapi/slack-github-action@v1.21.0
with:
channel-id: ${{ env.CHANNEL_NAME }}
slack-message: ""I am a Test message"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
channel_name: ${{ github.event.client_payload.channel_name }}
In your example, you used the syntax $env:channel_name
. This only works on a Windows runner. On Linux or macOS you will want to use ${{ env.CHANNEL_NAME }}
.
my runner is Windows based.
However like the error above when setting it as:
with:
channel-id: $env:channel_name
I get the error: Error: An API error occurred: channel_not_found`
When I set it like your example with ${{ env.CHANNEL_NAME }}
it worked even though my runner is not linux based. So i guess Windows Runners also want the ENV in that format.
Here's my final example
- name: Post to Slack
id: slackinitial
uses: slackapi/slack-github-action@v1.21.0
with:
channel-id: ${{ env.CHANNEL_NAME }}
slack-message: ""I am a Test message"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
channel_name: ${{ github.event.client_payload.channel_name }}
for others that come across this my client_payload comes from a JSON based HTTP Post from a web endpoint
Thank you for the assistance! Maybe we can update the readme with this example for others to come across.
Hey @jku-sr! So glad to hear we could help. Since the specific issue seems to be resolved I'll close it off.
Feel free to reopen it if there's still any problems with this specific issue. If you need help with something else you can create a new issue 👍
Description
can Channel_ID be set using an environmental variable?
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version:
node version:
OS version(s):
Steps to reproduce:
my workflow YAML
Expected result:
channel-id will pickup the environmental variable. Looking at the output the environmental variable is being picked up but channel-id I guess only takes Strings literally.
Actual result:
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.