Search code examples
jenkinsjenkins-pipelinejenkins-plugins

Email Plugin on Jenkins Pipelines


I installed the Email Extension Plugin (2.66) for Jenkins (2.176.3) to use in Pipelines and I'm trying the example on: https://medium.com/@gustavo.guss/jenkins-sending-email-on-post-build-938b236545d2

pipeline {
    environment {
        //This variable need be tested as string
        doError = '1'
    }

    agent any

    stages {
        stage('Error') {
            when {
                expression { doError == '1' }
            }
            steps {
                echo "Failure"
                error "failure test. It's work"
            }
        }

        stage('Success') {
            when {
                expression { doError == '0' }
            }
            steps {
                echo "ok"
            }
        }
    }
    post {
        always {
            echo 'I will always say Hello again!'

            emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
                recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
                subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"

        }
    }
}

But I have the following error :

Error when executing always post condition: java.lang.NoSuchMethodError: No such DSL method 'emailext' found among steps [VersionNumber, acceptGitLabMR, addGitLabMRComment, archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, envVarsForTool, error, fileExists, findFiles, getContext, ...

Also I cannot configure the plugin itself and I do not know how to activate it, I restarted Jenkins, the system and did not work , the pipeline syntax editor does not recognize the plugin, any suggestions ?


Solution

  • By some reason my Jenkins server in the plugins folder had the file: email-ext.jpi.disabled and removing that file, the pipeline syntax editor started to recognize the plugin itself... well I do not have the message of 'no such DSL method emailext' anymore

    Testing with the example of Marat Sending a Mail on Jenkins Pipeline