KocproZ / jenkins-discord

A post-build plugin that sends the build status to a Discord channel.
MIT License
39 stars 36 forks source link

Default non Jenkisfile webhook Look in a jenkinsfile project? #23

Open kingdevnl opened 6 years ago

kingdevnl commented 6 years ago

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

jupjohn commented 6 years ago

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 commented 5 years ago

@KocproZ bump

KocproZ commented 5 years ago

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.