Skip to content

Commit 1cfed1b

Browse files
authored
Allow user file upload to work (#967)
1 parent 62ffe7c commit 1cfed1b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ node {
143143

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

146+
##### File upload to a user channel
147+
148+
You can upload files to a user channel by messaging the user first and then using the channel ID from the message response:
149+
150+
```groovy
151+
node {
152+
sh "echo hey > blah.txt"
153+
def slackResponse = slackSend channel: '$userId', message: 'Hey', sendAsText: true
154+
slackUploadFile filePath: "*.txt", channel: slackResponse.channelId
155+
}
156+
```
157+
146158
#### Threads Support
147159

148160
You can send a message and create a thread on that message using the pipeline step.

src/main/java/jenkins/plugins/slack/pipeline/SlackUploadFileStep.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,11 @@ protected Void run() throws IOException, InterruptedException, ExecutionExceptio
141141

142142
String channelId;
143143
try {
144-
channelId = SlackChannelIdCache.getChannelId(populatedToken, cleanChannelName(channel));
144+
String channelName = cleanChannelName(channel);
145+
channelId = SlackChannelIdCache.getChannelId(populatedToken, channelName);
145146
if (channelId == null) {
146-
String message = "Failed uploading file to slack, channel not found: " + channel;
147-
if (step.failOnError) {
148-
throw new AbortException(message);
149-
} else {
150-
listener.error(message);
151-
return null;
152-
}
147+
// possibly a user ID which won't be found in the channel ID cache
148+
channelId = channelName;
153149
}
154150
} catch (CompletionException | SlackChannelIdCache.HttpStatusCodeException e) {
155151
throw new AbortException("Failed uploading file to slack, channel not found: " + channel + ", error: " + e.getMessage());

0 commit comments

Comments
 (0)