jenkins-discord icon indicating copy to clipboard operation
jenkins-discord copied to clipboard

Default non Jenkisfile webhook Look in a jenkinsfile project?

Open kingdevnl opened this issue 6 years ago • 3 comments

How could i make the embed in a Jenkinsfile pipeline build Look the same as a default embed from a freestyle build?

kingdevnl avatar Jun 18 '18 08:06 kingdevnl

I don't use pipelines myself so I think you're gonna have to play around and come back to me on that one. I'm sure there are variables exposed to the pipeline steps that you could access and use.

jupjohn avatar Aug 14 '18 07:08 jupjohn

@KocproZ bump

jupjohn avatar Nov 07 '18 04:11 jupjohn

I don`t know (yet) if it is doable in plugin itself, but I can give you a snippet that I created for other project:

        def artifactUrl = env.BUILD_URL + "artifact/"
        def msg = "**Status:** " + currentBuild.currentResult.toLowerCase() + "\n"
        msg += "**Branch:** ${BRANCH_NAME}\n"
        msg += "**Changes:** \n"
        if (!currentBuild.changeSets.isEmpty()) {
            currentBuild.changeSets.first().getLogs().each {
                msg += "- `" + it.getCommitId().substring(0, 8) + "` *" + it.getComment().substring(0, it.getComment().length()-1) + "*\n"
            }
        } else {
            msg += "no changes for this run\n"
        }

        if (msg.length() > 1024) msg.take(msg.length() - 1024)

        def filename
        msg += "\n **Artifacts:**\n"
        currentBuild.rawBuild.getArtifacts().each {
            filename = it.getFileName()
            msg += "- [${filename}](${artifactUrl}${it.getFileName()})\n"
        }

        withCredentials([string(credentialsId: 'discord_webhook', variable: 'discordWebhook')]) {
            discordSend thumbnail: "https://static.kocproz.ovh/warp-logo.png", successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), description: "${msg}", link: env.BUILD_URL, title: "Warp_Engine:${branch} #${BUILD_NUMBER}", webhookURL: "${discordWebhook}"
        }

It produces this: image

Just modify some fields and you're good to go.

KocproZ avatar Nov 07 '18 23:11 KocproZ