CircleCI-Public / slack-orb

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

feat: add windows support #380

Closed EricRibeiro closed 1 year ago

EricRibeiro commented 1 year ago

Motivation

This PR will add support for the Windows Executor.

Changes

For unknown reasons, CircleCI cannot parse the Slack script from the YAML without error-ing out in the Windows Executor. This PR adds a layer of indirection in the script execution by saving it to a variable and subsequently executing it with eval printf from another script.

While this doesn't fix the underlying issue in the platform, nor is it a pretty solution, it will add Windows capability with minimal modifications.

Additionally, this PR adds a conditional to slightly modify one of awk's regex since Windows is complaining about using backslashes. It also sets debug to true for all tests so we can quickly see request and response payloads from the web app.

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:b78a659fe66960c3fbb769bf19d5ec7860e8614a

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:b78a659fe66960c3fbb769bf19d5ec7860e8614a

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:4b6c8db6cb8ab6ccc89e7d4a6e6f685c1fbe429b

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:7825ae967d83b6283cd6a63126ce5c1562b6ecf7

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:0b15bd3d7bfa3b6a2e0f33bb8a7956cc911b91c8

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:1a6bb6df2c4c147e3742ded5af62584a2dc3df43

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:a33171dd239591891ad45df0fcb6ec942be59f42

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:a6efb8e36dd8c7cbf7c57efa46475ae8d4e565a0

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:afb96bdc65cc9ab561de90232ce6f6e35b7869c3

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=dev:afb96bdc65cc9ab561de90232ce6f6e35b7869c3

orb-publisher commented 1 year ago

Your orb has been published to the CircleCI Orb Registry. You can view your published orb on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/slack?version=4.12.0

moolitayer commented 1 year ago

Could this be the cause of a new issue? I'm consistently seeing this in my workflow output:

#!/bin/bash -eo pipefail
#!/usr/bin/env sh

# Workaround for Windows Support
# For details, see: https://github.com/CircleCI-Public/slack-orb/pull/380
# shellcheck source=/dev/null
eval printf '%s' "$SLACK_SCRIPT_NOTIFY"

Posting Status
BASH_ENV file: /tmp/.bash_env-6387174eb5adcd7a32efc3d4-0-build
Exists. Sourcing into ENV
Checking For JQ + CURL

Exited with code exit status 1
CircleCI received exit code 1
EricRibeiro commented 1 year ago

@moolitayer, could you please open an issue with the orb version, executor and output you see with the debug parameter set to true?

martin-displayr commented 11 months ago

How do I use this. If I run this orb on a Windows executor I get:

eval : The term 'eval' is not recognized as the name of a cmdlet, function, script file, or operable program. Check 
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:6 char:1
+ eval printf '%s' "$SLACK_SCRIPT_NOTIFY"
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (eval:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Exited with code exit status 1
EricRibeiro commented 11 months ago

@martin-displayr, have you tried setting your shell to bash.exe?

martin-displayr commented 11 months ago

Thanks @EricRibeiro , that helps on a job that only has the slack notification.

But I have a job that needs the shell to be Powershell. And I don't think I can switch shell types in a step. And of course if I use a different job I don't have access to the failure state (at least not easily).

I have raised an issue: https://github.com/CircleCI-Public/slack-orb/issues/429

martin-displayr commented 11 months ago

I would say that is a bug, the orb should be able to specify it needs bash, and not just use the default shell. As a workaround I have changed the job default shell and changed all my run commands to

      - run: 
          shell: powershell.exe
      ...

But that is a bit ugly to have to do just to get slack integration.