jenkinsci / slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
https://plugins.jenkins.io/slack/
MIT License
670 stars 413 forks source link

Support for addReaction/removeReaction with threadId and ts #944

Closed cf-sewe closed 7 months ago

cf-sewe commented 8 months ago

What feature do you want to see added?

I would like to add/remove reactions in a post step. Currently this is seemingly only possible via the response object. Therefore I would like to add the reaction emoji using stored ThreadId and Timestamp.

Alternatively, is there a way to store and share the slackResponse between different stages? I tried this approach, unsuccessful.

Upstream changes

No response

Are you interested in contributing this feature?

No response

timja commented 8 months ago

It should be quite straightforward, just add a new step for it.

cf-sewe commented 8 months ago

I am not sure how you mean this. I get an error that slackResponse is not defined in my post step:

  post {
    always {
      script {
        slackResponse.removeReaction("hourglass_flowing_sand")
        def statusEmoji = currentBuild.result == 'SUCCESS' ? "white_check_mark" : "x"
        def statusColor = currentBuild.result == 'SUCCESS' ? green : red
        def message = "Execution of pipeline completed with status ${currentBuild.result}, duration ${currentBuild.durationString}."
        slackResponse.addReaction(statusEmoji)
        slackSend(
          channel: slackResponse.threadId,
          color: statusColor,
          message: message
        )
      }
    }
  }

slackResponse has been defined in a previous step.

timja commented 8 months ago

i mean adding a new step for it

cf-sewe commented 7 months ago

I did not understand what timja meant. However I used a workaround which resolves the issue for me.

Now I declare the required variable on top level of the declarative pipeline. Then I can use the declared variable in each step, to update the Slack notification reactions.