slack-orb: Windows support not working in version 4
Orb version: 4.1.1
What happened:
Based on discussion in https://github.com/CircleCI-Public/slack-orb/issues/145, we upgrade our slack orb usage to version 4.
We have a job that runs on the windows executor:
<job name>:
executor:
name: win/default
shell: powershell.exe
steps:
...
- slack/notify:
channel: <channel id>
event: fail
template: basic_fail_1
What we see is:
At line:1 char:18
+ BuildMessageBody() {
+ ~
An expression was expected after '('.
At line:6 char:7
+ if [ -n "$SLACK_PARAM_CUSTOM" ]; then
+ ~
Missing '(' after 'if' in if statement.
At line:6 char:9
+ if [ -n "$SLACK_PARAM_CUSTOM" ]; then
+ ~
Missing type name after '['.
At line:26 char:13
+ PostToSlack() {
+ ~
An expression was expected after '('.
At line:31 char:8
+ for i in $(eval echo \""$SLACK_PARAM_CHANNEL"\" | sed "s/,/ /g")
+ ~
Missing opening '(' after keyword 'for'.
At line:32 char:7
+ do
+ ~
Missing statement body in do loop.
At line:37 char:11
+ --data \
+ ~
Missing expression after unary operator '--'.
At line:37 char:11
+ --data \
+ ~~~~
Unexpected token 'data' in expression or statement.
At line:37 char:15
+ --data \
+ ~
The Data section is missing its statement block.
At line:38 char:27
+ ... "$SLACK_MSG_BODY" https://slack.com/api/chat.postMessage | jq '{ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'https://slack.com/api/chat.postMessage' in expression or statement.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
Exited with code exit status 1
Expected behavior:
For the notification to be sent successfully, like it is on the linux and macOS executors.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (3 by maintainers)
Hey, @tom-james-watson and @Kurt-von-Laven 👋
Support for Windows was implemented in v4.12.0. If you want to give it a shot, make sure to choose
bash.exeas your shell in the Windows executor.Let me know how it goes!
@Kurt-von-Laven You’re right, I don’t know why I thought completely reimplmenting the script in PowerShell was optimal – for some reason, a few of us were under the impression that simply setting
bashas the shell would break things, and it’s likely this used to be the case, but it appears that just setting the shell for the steps works fine in #282. Moving forward with this approach.I would like to challenge the notion that PowerShell support is important. Windows support is important, and the Windows image ships with bash. I believe the simplest solution would be to permit a default shell to be specified consistently on all platforms. The Slack orb is not the only orb that would benefit from this.
In the meantime, here is a better workaround. It turns out the use of artifacts is unnecessary, and it’s risky to assume that the most recent completed job on the same branch is the correct job to report the status of. A better solution is to search for the most recent completed job with the same commit hash using the CircleCI API. This also enables propagation of cancellations to the notify job. Put the following code in .circleci/trickSlackOrb.sh:
Include an extra job in your .circleci/config.yml that runs the script and issues the Slack notification:
For future reference, version 4 of the slack orb does not work in Windows. This is also mentioned with more context in the wiki’s FAQ section.
It mostly works out of the box - we’ve noticed a minor issue with our sed syntax when trying to escape templates for execution, and trying to get to the bottom of it. For the most part, though, it does just work, thankfully.
Yeah, I believe it’s possible to specify
shell: bash.exefor individual jobs, so that’s what I had been expecting would be the case for windows support. If the plan is to eventually support this then I would leave this open as a feature request so people can track it.