Slack plugin

2 minute readExtensibilityDeveloper productivity
On this page

Slack is a business messaging application that connects people to the information they need. By bringing people together to work as one unified team, Slack transforms the way organizations communicate.

The Slack plugin implements the integration with Slack using the incoming webhook interface that allows CloudBees CD/RO to send messages to a Slack channel. Refer to Slack incoming webhooks for more information.

Prerequisites

When upgrading the Slack plugin from version from 1.x to 2.x, you must update your pipeline procedures and tasks to use the new version. This can be a lengthy process. To help reduce the overhead involved, you can also run the following code to perform these tasks.

If you need help running the code, refer to Get started with DSL.
View code
procedure 'Upgrade tasks & steps EC-Slack 1.x to EC-Slack 2.x ', {
projectName = 'Default'
timeLimit = '0'

  step 'Upgrade tasks & steps', {
    command = '''import com.electriccloud.client.groovy.ElectricFlow
import com.electriccloud.client.groovy.models.ActualParameter

ElectricFlow ef = new ElectricFlow()

def projects = ef.getProjects()
projects.project.each { projectEntity ->
if (projectEntity.pluginKey == null || projectEntity.pluginName == null) {
println "Working on project: " + projectEntity.projectName
def pipelinesResult = ef.getPipelines(projectName: projectEntity.projectName)
pipelinesResult.pipeline.each { pipeline ->
println "... Working on pipeline: " + pipeline.pipelineName
def stages = ef.getStages(projectName: projectEntity.projectName,
pipelineName: pipeline.pipelineName)
stages.stage.each { stage ->
println "...... Working on stage: " + stage.stageName
def tasks = ef.getTasks(projectName: projectEntity.projectName,
pipelineName: pipeline.pipelineName,
stageName: stage.stageName)
tasks.task.each { task ->
println "......... Working on task: " + task.taskName
if (task.subpluginKey == "EC-Slack") {
println "............ Task matched "
def parameterDetails = task.actualParameters.parameterDetail
def List<ActualParameter> actualParameterArray = new ArrayList<ActualParameter>()

                        parameterDetails.each {
                            parameter ->
                                if (parameter.parameterName == "config" || parameter.parameterName == "payload") {
                                    def actualParameter = new ActualParameter()
                                    actualParameter.setActualParameterName(parameter.parameterName)
                                    actualParameter.setValue(parameter.parameterValue)
                                    actualParameterArray.add(actualParameter)
                                }
                                if (parameter.parameterName == "payload-msg") {
                                    def actualParameter = new ActualParameter()
                                    actualParameter.setActualParameterName("payload")
                                    actualParameter.setValue(parameter.parameterValue)
                                    actualParameterArray.add(actualParameter)
                                }
                        }
                        def result = ef.modifyTask(projectName: projectEntity.projectName,
                                pipelineName: pipeline.pipelineName,
                                stageName: stage.stageName,
                                taskName: task.taskName,
                                actualParameters: actualParameterArray,
                                clearActualParameters: true)
                        println "............ Task updated "
                        println "............ New parameters:" + actualParameterArray
                    }

                }
            }
        }
        def procedures = ef.getProcedures(projectName: projectEntity.projectName)
        if (procedures.size() != 0) {
            procedures.procedure.each { procedure ->
                println "... Working on procedure: : " + procedure.procedureName
                def steps = ef.getSteps(
                        projectName: projectEntity.projectName,
                        procedureName: procedure.procedureName
                )

                steps.step.each { step ->
                    def parameters = ef.getActualParameters(
                            projectName: projectEntity.projectName,
                            procedureName: procedure.procedureName,
                            stepName: step.stepName)
                    println "...... Working on step: : " + step.stepName
                    if (step.subproject == \'/plugins/EC-Slack/project\') {
                        println "............ Step matched "
                        def List<ActualParameter> actualParameterArray = new ArrayList<ActualParameter>()
                        def details = parameters.actualParameter
                        parameters.actualParameter.each {
                            parameter ->
                                if (parameter.actualParameterName == "config" || parameter.actualParameterName == "payload") {
                                    def actualParameter = new ActualParameter()
                                    actualParameter.setActualParameterName(parameter.actualParameterName)
                                    actualParameter.setValue(parameter.value)
                                    actualParameterArray.add(actualParameter)
                                }
                                if (parameter.actualParameterName == "payload-msg") {
                                    def actualParameter = new ActualParameter()
                                    actualParameter.setActualParameterName("payload")
                                    actualParameter.setValue(parameter.value)
                                    actualParameterArray.add(actualParameter)
                                }

                        }
                        def result = ef.modifyStep(
                                projectName: projectEntity.projectName,
                                procedureName: procedure.procedureName,
                                stepName: step.stepName,
                                actualParameters: actualParameterArray,
                                clearActualParameters: true
                        )
                        println "............ Step updated "
                        println "............ New parameters:" + actualParameterArray
                    }
                }
            }
        }
        println "==============================================="
    }

}'''
shell = 'ec-groovy'
timeLimit = '0'
timeLimitUnits = 'seconds'
}
}