Created
September 4, 2018 19:49
-
-
Save bkruger99/f810101853f2dfca64c5c753dde07824 to your computer and use it in GitHub Desktop.
Generate a user token for the new jenkins subsystem (works in 2.139+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.security.* | |
import jenkins.security.apitoken.* | |
def username = '<pre-existing user goes here>' | |
def token = '<what you want to name your token>' | |
User u = User.get(username) | |
ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); | |
ApiTokenStore.TokenUuidAndPlainValue tokenUuidAndPlainValue = p.tokenStore.generateNewToken(token); | |
u.save() | |
// Here's the token output value. | |
println tokenUuidAndPlainValue.plainValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment