jenkinsci / hipchat-plugin

HipChat notification plugin for Jenkins
https://plugins.jenkins.io/hipchat/
54 stars 85 forks source link

Configure Hipchat from code #111

Closed ibrahim-alzant closed 7 years ago

ibrahim-alzant commented 7 years ago

I initialise my Jenkins through initialisation script under (init.groovy.d) which bootstrap the Jenkins and install the plugins along with configuring them. I was wondering how can configure hipchat plugin in the same way setting up the token, server ... etc.

luchianenco commented 7 years ago

You should access hipchat plugin and set you settings...I am currently still working on this script and Notification message configs are not yet ready. I post here what was working for me

import jenkins.*
import jenkins.model.*
import hudson.model.*
import java.util.logging.Logger
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.domains.*
import hudson.util.Secret
import jenkins.plugins.hipchat.model.*
import org.jenkinsci.plugins.plaincredentials.impl.*
import jenkins.plugins.hipchat.model.notifications.Notification.Color

uuid = java.util.UUID.randomUUID().toString()
secret = new Secret("{{ hipchat_secret }}")
c = new StringCredentialsImpl(CredentialsScope.GLOBAL, uuid, "{{ hipchat_credential_description }}", secret)

SystemCredentialsProvider.getInstance().getStore().addCredentials(Domain.global(), c)

def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("jenkins.plugins.hipchat.HipChatNotifier")

desc.setServer("{{ hipchat_api_server }}")
desc.setCredentialId(uuid)
desc.setRoom("{{ hipchat_room_id }}")
desc.setV2Enabled(true)
ibrahim-alzant commented 7 years ago

worked like a charm, Thanks!

luchianenco commented 7 years ago

you are wecome ;)