Jenkins pipeline upload file to Slack

I have a Jenkins pipeline that sends an alert to Slack. Now I want to add the ability to upload files to Slack. But the file is not sent.

This is sending messages to slack. And it works.

slackSend(
    color: color_slack_msg(),
    message: """
        Some message
    """.stripIndent().trim(),
    channel: "${env.SLACK_ID}, ${env.SLACK_NOTIFICATION_ID}",
    tokenCredentialId: 'slack_notification'
)

This is a file upload to Slack.

slackUploadFile (
    channel: '${env.SLACK_METRICS_ID}', 
    credentialId: 'slack_notification', 
    filePath: 'metrics_editor.txt', 
    initialComment: 'Test comment'
)

After executing the slackUploadFile script, I see the message in the Jenkins logs:

Using dirname=somepathtoproject and includeMask=metrics_editor.txt
Adding file somepathtoprojectmetrics_editor.txt

But the file is not uploaded to Slack.

I see that Credential is configured correctly since slackSend is working.

I tried this:

curl -sSL -D - -X POST -F file=@<path_to_file> -F token=<bot_token> https://slack.com/api/files.upload

In response I receive:

file=@metrics_editor.txt -F channels=<channel id> -F token=<token>https://slack.com/api/files.upload
HTTP/1.1 200 OK
date: Thu, 21 Sep 2023 14:37:51 GMT
server: Apache
vary: Accept-Encoding
x-slack-req-id: <id>
x-content-type-options: nosniff
x-xss-protection: 0
x-robots-tag: noindex,nofollow
pragma: no-cache
cache-control: private, no-cache, no-store, must-revalidate
expires: Sat, 26 Jul 1997 05:00:00 GMT
content-type: application/json; charset=utf-8
access-control-expose-headers: x-slack-req-id, retry-after
access-control-allow-headers: slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-slack-unique-id: <id>
x-slack-backend: r
referrer-policy: no-referrer
access-control-allow-origin: *
content-length: 35
via: 1.1 slack-prod.tinyspeck.com, envoy-www-iad-maoxshte, envoy-edge-fra-uzwtdosi
x-envoy-attempt-count: 1
x-envoy-upstream-service-time: 101
x-backend: files_normal files_canary_with_overflow files_control_with_overflow
x-server: slack-www-hhvm-files-iad-xskh
x-slack-shared-secret-outcome: no-match
x-edge-backend: envoy-www
x-slack-edge-shared-secret-outcome: no-match

{"ok":false,"error":"invalid_auth"}

I also found that in the settings of the Jenkins application in Slack you need to give permissions to upload files files:write, but I don’t know where to find this permission.
I found Jenkins in Installed Applications, but the permissions page is empty.

enter image description here

it might be bug in plugin, as i see slack endpoints were changed recently

it doesnt work with simple token(jenkins ci webhook) by some reason but works with slack application bot token

i tested this:

node {
    sh "echo hey > blah.txt"
    slackUploadFile filePath: "*.txt", channel: "#testing-slack-api", initialComment:  "HEY HEY", credentialId: "slack-bot-token"
}

where slack-bot-token is token from slack app “Bot User OAuth Token”.

you can pass token from code, or configure it globally in jenkins global settings -> slack
and slack app configured via https://plugins.jenkins.io/slack/#plugin-content-creating-your-app

also added app to slack channel as @myappname -> yes, invite app to channel

you can find your slack apps via

  1. go to any channel you have and click on name
  2. go to integration tab
  3. press add apps
  4. press manage apps (top left corner)
  5. click Build on top right corner
  6. press Create New App
  7. everything else you can find in documentation

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật