0

I am new to Jenkins, exploring......

My problem statement is, After Jenkins execution, a text file(Output.txt) is being generated into Workspace. The requirement is, I want to copy the contents of that .txt file and print it on Slack notification message.

I tried to create an "Execute Shell" inside that I wrote:

echo myVar=Property \> Something\\bin\\Release\\Output.txt

After that I used the EnvInject plugin, inside that in properties file path I have given the full path of Output.txt

In post-build build-action, I have selected Slack notification, in custom message I have written:

Data is- $myVar
Data is- $Property

Now When I am executing this Job I got Slack Notification, but didn't got the data of Output.txt.

I got this on Slack:

Data is- $myVar
Data is- $Property

What I am expecting, if Output.txt hold hello world then I want:

Data is - hello world

in Slack notification.

tijko
  • 7,599
  • 11
  • 44
  • 64
  • There is a plugin with simple usage of sending slack notifications via Jenkins... https://plugins.jenkins.io/slack/ – Barel elbaz Apr 06 '22 at 06:58
  • Thanks for your Answer. I know that but how to use the Contents of a text file that is in Jenkins Workspace into the Slack Notification plugin. – vivek joshi Apr 06 '22 at 10:42
  • Do you want to attach it as a file or reading and writing to a message? – Barel elbaz Apr 06 '22 at 11:03
  • No, I do not want to attach the file with a slack notification. The Only thing I want is to print the content of Output.txt in Slack Notification. So, My Concern is about how to fetch the data from that Output.txt(Basically this file holds some data which is coming from API ) and print it into Slack (With the help of the plugin present in Post-build Action). Thanks in Advance!! – vivek joshi Apr 07 '22 at 09:29

1 Answers1

0

upload file .txt

Read .txt in jenkins

I think the best option is to read the .txt in jenkins, pass it to a variable and place it in the notification

Alex Bravo
  • 25
  • 3
  • Thanks for the Answer Alex, Would you please elaborate on how to read a text file from Jenkins Workspace and store it in a variable (As the Content inside Output.txt might be of Multiple Strings ). And how to use that Variable in the Slack Notification Part. (As One Variable defined in One section bounded within the Section). Thanks in Advance!! – vivek joshi Apr 07 '22 at 09:51