I have downloaded & installed Slack Notification Plugin in jenkins and using slackSend in the pipeline, it was working before but now getting an error as below: After this i downloaded Global Slack Notifier plugin, but still the same error,is there any setup required? Please advice
[Pipeline] slackSend
run slackstepsend, step null:false, desc null:false
Slack Send Pipeline step configured values from global config - baseUrl: true, teamDomain: true, token: true, channel: false, color: false
ERROR: Slack notification failed. See Jenkins logs for details.
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE
Code is as below:
if (dstry) {
def status = sh(returnStatus: true, script: "set +e; terraform plan -destroy -var-file=my.tfvars -out=destroy.tfplan")
echo "Plan Status : ${status}"
def destroyExitCode = sh(returnStatus: true, script: "set +e; terraform destroy -auto-approve")
echo "Terraform Destroy Exit Code: ${destroyExitCode}"
if (destroyExitCode == "0") {
slackSend channel: '#ci', color: 'good', message: "Destroy Applied ${env.JOB_NAME} - ${env.BUILD_NUMBER} ()"
currentBuild.result = 'SUCCESSFUL'
} else {
slackSend channel: '#ci', color: 'danger', message: "Destroy Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER} ()"
currentBuild.result = 'FAILURE'
}
}
Did you add the slack Jenkins token for integration?
Go to this Jenkins CI url, search for your team domain, then add a new configuration. Copy the name of the token or the token itself. Then go to your Jenkins pipeline script and add to slackSend, the domain and the token credential ID or the token in plain text (not secured). Should look something like this:
slackSend channel: '#ci', color: 'good', message: "Destroy Applied ${env.JOB_NAME} - ${env.BUILD_NUMBER}", teamDomain: 'your_domain.slack.com', tokenCredentialId: 'your_id'
or if you want to use the token in plain text token:'your_token' instead of the tokenCredentialId
Hope this helps!
Related
im trying to post Jenkins job script output to slack notification: but i cant able to access the output in slack notification setting.
other than /env-vars.html/ the variables here i can't able to access any other variable.
At the moment there is no support to get the variables other than env vars in Jenkins. We can use "Environment Injector" plugin but I am not sure about that plugin.
For your case you can create a "Pipeline" with the below scripted pipeline
node('JENKINS_NODE') {
git([url: 'GITHUB_REPO_URL', branch: 'BRANCH'])
def getResult
stage ('Execute Script') {
getResult = sh(
script: "python test.py",
returnStdout: true,
)
}
stage ('Send Slack Notification') {
slackSend channel: '#YOUR_SLACK_CHANNEL', color: 'good', message: getResult'
}
}
I have a groovy slacksend function to notify to slack channels.
slackSend(
channel: "#channel-name",
color: "warning",
message: "Could not confirm server started - ${env.BRANCH} (<${env.BUILD_URL}/console|Details> - <${SERVER_URL}|Open>)"
)
But the output is something like this
[Pipeline] slackSend
run slackstepsend, step null:false, desc :true
Slack Send Pipeline step configured values from global config - baseUrl:
true, teamDomain: true, token: true, channel: false, color: false
and there is not notification being sent. Any idea?
Those values in your pipeline output should be getting populated with the values from your jenkinsfile. eg, teamDomain: true should be teamDomain: <your_slack_team>. You can pass each of these as a parameter in the slacksend invocation in your Jenkinsfile just as you are with channel, color, and message. Also, your channel name doesn't require #, though i don't know if that would cause it to fail.
slackSend channel: '#yourchannelname', color: color, message: 'Starting branch', teamDomain: 'your_enterprise_team_domain', token: 'token_generated_from_jenkins_slack_integration'
Can I use slackSend command in jenkins flow dsl if i have Jenkins ver. 1.656.
I have enabled Slack Notification Plugin and it works fine in most cases, but i wish to display message when build starts.
You can set up script in the pipeline, should be something like this:
def notify(status) {
slackSend channel: "#jenkins",
color: '#d71f85',
message: "${status}",
tokenCredentialId: 'yourtoken'
}
pipeline{
....
stages{
stage('Buildstart) {
steps {
notify("Build Started")
}
}
....
}
}
I have a Jenkinsfile that is running a shell command and I want to send the output of that sh method as the message: of the slackSend method.
I have the following so far, but the message to the slack channel is empty. I'm not certain how to capture the output in a way that I can reference it in the message section:
node {
checkout scm
stage 'run shell command'
def shell_command = sh "ls -l"
def shell_output = apply_cluster
stage 'notify slack-notification'
slackSend channel: '#slack-notifications', color: 'good', message: shell_output, teamDomain: 'company', token: env.SLACK_TOKEN
}
After a little more research, I discovered a couple of things I did not initially understand: The first is that even with defining a function in a Jenkinsfile, if it's a DSL method like sh, it will still get executed, so the second function I defined isn't necessary. Second, if you want to return stdout, you have to specify that as part of the command. The new code looks like this:
node {
checkout scm
stage 'run shell command'
def shell_command = sh script: "ls -l", returnStdout: true
stage 'notify slack-notification'
slackSend channel: '#slack-notifications', color: 'good', message: shell_command, teamDomain: 'company', token: env.SLACK_TOKEN
}
I have 'Slack Notification Plugin' installed in Jenkins.
It configured to notify when Build fails or Build success.
For example with such a message:
jenkins BOT [9:00 PM]
----------------
web-services tests - #58 Success after 1 min 38 sec (</job/web-services%20tests/58/|Open>)
Is it possible to customize message? I want to have something like this:
jenkins BOT [9:00 PM]
----------------
web-services tests - #58 Success after 1 min 38 sec (USER_NAME)
thank you in advance.
If you use jenkins 2.0 you can change massage something like this:
slackSend color: 'good', message: 'Message from Jenkins Pipeline'
Or something like this in UI
You can use Jenkinsfile and every configuration will be in your vcs.
node {
try {
notifyStarted()
stage 'Checkout'
sh gg
stage 'Build'
sh xx
stage 'Deploy'
sh yy
notifySuccessful()
} catch(e) {
currentBuild.result = "FAILED"
notifyFailed()
}
}
def notifyStarted() {
slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
def notifySuccessful() {
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
def notifyFailed() {
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}