Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jenkinsci/slack-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 714.v62ffe7c796cd
Choose a base ref
...
head repository: jenkinsci/slack-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 715.v1cfed1b_9c63c
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on May 9, 2024

  1. Allow user file upload to work (#967)

    timja authored May 9, 2024
    Copy the full SHA
    1cfed1b View commit details
Showing with 16 additions and 8 deletions.
  1. +12 −0 README.md
  2. +4 −8 src/main/java/jenkins/plugins/slack/pipeline/SlackUploadFileStep.java
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -143,6 +143,18 @@ node {

This feature requires [botUser](#bot-user-mode) mode.

##### File upload to a user channel

You can upload files to a user channel by messaging the user first and then using the channel ID from the message response:

```groovy
node {
sh "echo hey > blah.txt"
def slackResponse = slackSend channel: '$userId', message: 'Hey', sendAsText: true
slackUploadFile filePath: "*.txt", channel: slackResponse.channelId
}
```

#### Threads Support

You can send a message and create a thread on that message using the pipeline step.
Original file line number Diff line number Diff line change
@@ -141,15 +141,11 @@ protected Void run() throws IOException, InterruptedException, ExecutionExceptio

String channelId;
try {
channelId = SlackChannelIdCache.getChannelId(populatedToken, cleanChannelName(channel));
String channelName = cleanChannelName(channel);
channelId = SlackChannelIdCache.getChannelId(populatedToken, channelName);
if (channelId == null) {
String message = "Failed uploading file to slack, channel not found: " + channel;
if (step.failOnError) {
throw new AbortException(message);
} else {
listener.error(message);
return null;
}
// possibly a user ID which won't be found in the channel ID cache
channelId = channelName;
}
} catch (CompletionException | SlackChannelIdCache.HttpStatusCodeException e) {
throw new AbortException("Failed uploading file to slack, channel not found: " + channel + ", error: " + e.getMessage());