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

Custom Message to accept user defined variables #359

Closed
navinjoy opened this issue Nov 30, 2017 · 7 comments
Closed

Custom Message to accept user defined variables #359

navinjoy opened this issue Nov 30, 2017 · 7 comments

Comments

@navinjoy
Copy link

navinjoy commented Nov 30, 2017

In the Jenkins build script I am exporting some data into a variable and want to use the value of that in Slack Custom Message but thats not working.

Ex:

Build script:
export myVar=hello

Slack Custom Message:
Your message is : $myVar

I can include jenkins env variables though...like... $BUILD_URL #

@navinjoy
Copy link
Author

navinjoy commented Dec 1, 2017

closing this issue, found an alternative way to handle this.

@navinjoy navinjoy closed this as completed Dec 1, 2017
@twall
Copy link

twall commented Jan 3, 2018

@navinjoy care to elaborate?

@ondrej-fabry
Copy link

And @navinjoy was never seen again.. sigh

@yuri-karpovich
Copy link

closing this issue, found an alternative way to handle this.

Can you share?

@dooleyb1
Copy link

Also looking for a solution to this, anyone solve?

@timja timja reopened this Jan 13, 2019
@xMort
Copy link

xMort commented Jan 31, 2019

I solved it via EnvInject plugin. Hopefully, you can use it in your setup.

First, I perform my build steps. Then in the dedicated shell builder, I write necessary data for custom notification text into the temporary file in the job workspace in the format of the key=value.

Next, I will use inject builder (from the plugin linked above) to inject content of the temporary file to the environment variables of the job (you can find values of these variables with rest of the variables in Environment variables tab of the job in Jenkins after it finishes).

I can then access the variables from the file in the Slack's custom notification text parameter.

- job-template: my-job-template
    name: '{folder}/{library}'
    ..other job properties
    builders:
        - checkout
		...some other build steps
        - shell: |
            ...some shell code
            FIRST_PROPERTY="some data from the processed job"
            SECOND_PROPERTY="some other data from the processed job"

            echo FIRST_PROPERTY=$(echo $FIRST_PROPERTY) >> $WORKSPACE/my-vars.properties
            echo SECOND_PROPERTY=$(echo $SECOND_PROPERTY) >> $WORKSPACE/my-vars.properties
        - inject:
              properties-file: $WORKSPACE/my-vars.properties
    publishers:
        - slack:
              room: '#my-slack-room'
              notify-success: true
              include-custom-message: true
              custom-message: 'The content of $FIRST_PROPERTY and $SECOND_PROPERTY'

@ArvinB
Copy link

ArvinB commented Mar 9, 2021

This does work for single lines, but for multiline environment variables using Envinject you have to have /n/ at the end of each line and what really doesn't work is if your line has leading spaces. This gets trimmed off. So if you custom message were to include a formatted xml or json or yaml then this doesn't work very well.

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

No branches or pull requests

8 participants