Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post jenkins build output (console output) to slack #57

Open
ffangliu opened this issue Mar 2, 2015 · 32 comments
Open

Post jenkins build output (console output) to slack #57

ffangliu opened this issue Mar 2, 2015 · 32 comments

Comments

@ffangliu
Copy link

ffangliu commented Mar 2, 2015

Jenkins generate some outputs for each build, which is shown in "Console output" panel for each build.
Can I make the slack-plugin post that output to slack? Is this feature already available?

I tried checking the box " Include Test Summary" in the slack notification configuration. However, what I got on slack is "No Tests found."

@samrocketman
Copy link
Member

The Include Test Summary box is for including the results of JUnit tests. To see what that is supposed to look like when properly configured see pull request #25 because it has a screenshot.

Regarding including actual console output being posted to Slack; there is not currently a way for this to happen. I personally wouldn't find this useful but I don't use Jenkins nor the slack plugin (I only maintain pull requests and releases).

If this is a feature you truly want you're welcome to contribute it. I don't actively develop this project.

@peergum
Copy link
Contributor

peergum commented Mar 4, 2015

I concur with Sam. Our builds generate a lot of output (175k+) and this would have to be attached. I think it's a bit far from the notification purpose of the plugin and possibly a security issue too. The link in the slack post allows you to check the details of the build easily.

@rogthefrog
Copy link

I have a related issue. When Jenkins runs my python unit tests, the Slack message on failure is always "No Tests found" even though the console output shows Jenkins did find and run tests:

....F.F.....................FF.......
======================================================================
FAIL: test_xxx (xxx.module)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "xxx", line 1201, in patched
    return func(*args, **keywargs)
  File "xxx", line 95, in test_xxx
    assert rv.status_code == 200
AssertionError: 
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: INFO: Starting new HTTP connection (1): localhost
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 37 tests in 0.572s

FAILED (failures=4)
Build step 'Execute shell' marked build as failure
Setting commit status on GitHub for https://api.github.com/repos/xxx
Finished: FAILURE

What do I need to do for the Slack notifications to give me the correct output?

@samrocketman
Copy link
Member

@rogthefrog that's a separate issue (better to be opened in a new issue). That has to do with how Jenkins collects unit tests. By default Jenkins only collects JUnit tests from Java. It's part of the test collection. I'm not sure if there's a workaround for surfacing python unit tests in Jenkins.

@rogthefrog
Copy link

@samrocketman ok, will do. Thank you.

@gct-faisal
Copy link

There's no reason a hyperlink to the latest console output cannot be included
👉 http://[jenkins_server]/job/[job-name]/lastBuild/console 👈
in the custom message field.

@dejlek
Copy link

dejlek commented Aug 14, 2015

You can post the build log as a code snippet (that is actually the best option)!

@gct-faisal
Copy link

fabulous idea Dejan, can you point to any instructions on doing so?
thanks!

@nambrot
Copy link

nambrot commented Aug 18, 2015

+1

@dejlek
Copy link

dejlek commented Aug 19, 2015

No idea how, but I am assuming Slack API must give this option! :)

@nambrot
Copy link

nambrot commented Aug 19, 2015

So I know 0 about jenkins other than using it but it sounds like http://javadoc.jenkins-ci.org/hudson/model/Run.html#getLog(int) gives us what most of us want? and the text option for slacks api is https://api.slack.com/docs/attachments#text

@dejlek
Copy link

dejlek commented Aug 19, 2015

Yes, problem is that slack plugin for jenkins does not have this feature.

@scottillogical
Copy link

+1

@mikesigs
Copy link

I was just experiencing this problem too. After seeing here that this option only supports JUnit, I used the following work around.

I'm using xUnit to write my test results to an HTML file. So I just added a formatted link to the test results in the custom message.

<http://jenkins-server:port/job/JobName/ws/path/to/xunit/test/results.html|Test Results>

This puts a Test Results link in the Slack notification which (duh) I can click to see the nicely formatted xUnit test results html content.

@ezeeetm
Copy link

ezeeetm commented May 11, 2016

@mikesigs thanks. this was super helpful. Where do you see how to format messages like this? I was trying a regular href tag and it was not working as expected. Your method worked great.

@mikesigs
Copy link

@ezeeetm Glad it helped you! I found the info in the Slack API docs: https://api.slack.com/docs/formatting

@ezeeetm
Copy link

ezeeetm commented May 11, 2016

@mikesigs oh brother, now we have Slack Message Markup Language (SMML). The world already knew HTML! I guess (now that I look at it) there are some slack specific things that are easier to do this way. Thanks again!

@julia3
Copy link

julia3 commented Jan 27, 2017

Really want this feature!
@samrocketman Can I get an invite to slack channel? Thanks.

@samrocketman
Copy link
Member

There's an invite link on the README. Here's the link https://jenkins-slack-testing-signup.herokuapp.com

@jimthemighty
Copy link

I was able to get Slack to include the test results after I added the Publish Junit Test Result report.

@ssreyah
Copy link

ssreyah commented May 23, 2017

@jimthemighty , I was wondering if you could tell me how to set up slack to include the test results. Thank you

@jeetendra-choudhary
Copy link

Including $BUILD_URLconsole in the custom message field does the job for me.

@stolinzeev
Copy link

@jeetendra-choudhary the only problem with URL is when Jenkins located inside VPC and have no access without VPN. So you cannot use it on your mobile(you actualy can connect to vpn etc... but not workable at all)

@iranzo
Copy link

iranzo commented Nov 14, 2017

Same here, not for slack but for gerrithub, would be better than link to console, the actual console output of failed tests (or even all the output)

@timja
Copy link
Member

timja commented Nov 28, 2018

please reopen if still an issue, cleaning up the repo and this looks like it can be worked around easily, feel free to refile with a specific ask

@timja timja closed this as completed Nov 28, 2018
@DanEble
Copy link

DanEble commented Apr 1, 2019

The request was to include the console log in notifications. (I would add that limiting it to the last N lines of the log would be desirable.)

Calling currentBuild.rawBuild.getLog(int) triggers a sandbox access exception, so that is not an option.

Including a link to the log is a different use case, not a workaround.

Please reopen. Thanks.

@timja timja reopened this Apr 1, 2019
@timja
Copy link
Member

timja commented Apr 1, 2019

Not sure how possible this is in pipeline with slackSend, probably not too hard with freestyle to add it

@dsteinmo
Copy link

Why can't you just use the ${BUILD_LOG} jenkins macro in the custom message field?

@fho
Copy link

fho commented Jun 23, 2020

Why can't you just use the ${BUILD_LOG} jenkins macro in the custom message field?

@dsteinmo
$BUILD_LOG is not a variable set by jenkins, it's only available in the context of the email-ext plugin

@vivekkurhe05
Copy link

To get test summary on slack using protractor, you can use jasmine-reporters

var reporters = require('jasmine-reporters');

onPrepare: function () {
jasmine.getEnv().addReporter(new reporters.JUnitXmlReporter('outputdir/', true, true));
}

In jenkinsn, select "Publish JUnit test result report" from Post Build Actions and specify path to xml. In this case, *.xml

after test execution. you will see an informative test summary like this one
Screenshot from 2021-01-15 11-59-44

Also, don't forget to check "include test summary" one of the options from slack notifications plugin

@venkateshpanda
Copy link

Hi All,

Same question
We have the pipeline that sending the Jenkins to build notification to slack that success or failure.
But now we need the whole console output in text format to send the slack channel. Is there any way? Please anyone can help me here.

Thank you.

@vivekkurhe05
Copy link

Hi All,

Same question
We have the pipeline that sending the Jenkins to build notification to slack that success or failure.
But now we need the whole console output in text format to send the slack channel. Is there any way? Please anyone can help me here.

Thank you.

What test framework are you using? You should probably check JUnit XML reporter. It sends a test summary to the slack channel after test execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests