Skip to content

Instantly share code, notes, and snippets.

View RahulMahale's full-sized avatar
🏠
Working from home

Rahul Mahale RahulMahale

🏠
Working from home
View GitHub Profile
@RahulMahale
RahulMahale / groovy-create-user.md
Created August 6, 2021 09:14 — forked from hayderimran7/groovy-create-user.md
Jenkins Groovy enable security and create a user in groovy script

This is a snippet that will create a new user in jenkins and if security has been disabled , it will enable it :)

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount("MyUSERNAME","MyPASSWORD")
instance.setSecurityRealm(hudsonRealm)