3

I know how to notify build status using the slack notification plugin. I can seeproject - #buildnumber Success after 1 min 18 sec (Open) in my slack channel. But I want the console output to be sent to slack as well (upon failure) instead of a link. I am using free style project since I need some scripts to build my project. The purpose is that I want engineers to know the result of their build without granting them Jenkins access.

edit:

if console log can be uploaded as a text, would be also good. Other forms of 'output' would be welcome as well.

new edit:

I found the answer by myself.

4

I figured it out by myself, there is no plugin needed.

build.sh &> /dev/stdout | tee jenkins.txt and then curl -F file=@jenkins.txt -F channels=yourchannel -H "Authorization: Bearer your token" https://slack.com/api/files.upload

There is no '#' needed for slack channel and channel should not be private.

And if you use buils.sh | tee jenkins.log then you can't get the log from stderr.

  • This works great, thanks. For reference, you can post to a private channel if you create a bot, invite the bot to the private channel and use the bot token to upload the file. – pokkie Jun 21 at 9:26
1

You probably want the console output to be posted as an attachment, not a message, to slack. The post to slack plugin might be what you are looking for.

The other thing you could do is create a part of the freestyle job that strips out what you want to a text file, and add that as part of the slack message attachment, in the slack plugin configuration.

  • have you successfully set up what you mentioned? strip output to text + slack uploader. – tikael Oct 18 '18 at 19:28
1

Posting the full stack trace tends to clog up the channel. Here are a few things you can do:

  • Send build status along with the Jenkins Job link to the Channel so Devs can come back to the link for debugging
  • Send stack trace as a file
  • Send build status as and link to channel and Stack trace info to the user who committed the code for build

Either way, Post to Slack plugin along with other plugins will help you address this need.

  • what are other plugins? As I mentioned, devs won't be granted jenkins access. So I need a way to show log outside of jenkins – tikael Oct 19 '18 at 5:51
0

when i call the curl command to send my log file to Slack, i get error. make -j CoROS > /home/jenkins/co/log.txt

cat /home/jenkins/co/log.txt | tail -n 2 > /home/jenkins/co/log2.txt

echo /home/jenkins/co curl -F file=@log.txt -F channels=test-report -H "Authorization: Bearer XZyRSMmFaz-----------x0" https://slack.com/api/files.upload

Command: Started by user admin Building on master in workspace /home/jenkins/workspace_night [workspace_night] $ /bin/sh -xe /tmp/jenkins2437278061623352106.sh + echo <***** Start MAKE *****> <***** Start MAKE *****> + echo /home/jenkins/workspace_night /home/jenkins/workspace_night + cd build + make -j CoROS + echo /home/jenkins/co /home/jenkins/co + curl -F file=@log.txt -F channels=test-report -H Authorization: Bearer XZyRSMmFazL0EwNsB4xzPfx0 https://slack.com/api/files.upload % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 7792 0 35 100 7757 33 7508 0:00:01 0:00:01 --:--:-- 7509 {"ok":false,"error":"invalid_auth"}{"ok":false,"error":"invalid_auth"}{"ok":false,"error":"invalid_auth"} % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 curl: (43) A libcurl function was given a bad argument % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

New contributor
arshdeep kaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.