Skip to content

Instantly share code, notes, and snippets.

@imranity
Last active June 7, 2021 14:24
Show Gist options
  • Save imranity/dec6a655ba671fa5b3c3 to your computer and use it in GitHub Desktop.
Save imranity/dec6a655ba671fa5b3c3 to your computer and use it in GitHub Desktop.

Revisions

  1. imranity revised this gist Apr 21, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get-api-token-of-user-jenkins-groovy.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ This is pretty simple snippet to get API Token of a user , lets say "MYUser" in
    its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins,
    and you need to get the api token which JJB needs inorder to update jobs to ..
    run this code in either jenkins script console , or as i prefer, in form of init.groovy.
    so when jenkins amster starts, i create a user for JJb.
    so when jenkins master starts, i create a user for JJb.
    after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

    ```groovy
  2. imranity renamed this gist Mar 19, 2015. 1 changed file with 0 additions and 0 deletions.
  3. imranity revised this gist Mar 19, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion get-api-token-of-user-jenkins-groovy
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@ run this code in either jenkins script console , or as i prefer, in form of init
    so when jenkins amster starts, i create a user for JJb.
    after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

    ```
    ```groovy

    ///////////////////////////////////////////////////////////////////////
    import jenkins.security.*
    //j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    @@ -15,4 +16,5 @@ def token = t.getApiToken()
    //token.getClass()
    println "token is $token "
    ////////////////////////////////////////////////////////////////////////

    ```
  4. imranity revised this gist Mar 19, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion get-api-token-of-user-jenkins-groovy
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ run this code in either jenkins script console , or as i prefer, in form of init
    so when jenkins amster starts, i create a user for JJb.
    after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

    ```
    ///////////////////////////////////////////////////////////////////////
    import jenkins.security.*
    //j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    @@ -13,4 +14,5 @@ ApiTokenProperty t = u.getProperty(ApiTokenProperty.class)
    def token = t.getApiToken()
    //token.getClass()
    println "token is $token "
    ////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////
    ```
  5. imranity revised this gist Mar 19, 2015. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions get-api-token-of-user-jenkins-groovy
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,10 @@
    This is pretty simple snippet to get API Token of a user , lets say "MYUser" in jenkins , its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins, and you need to get the api token which JJB needs inorder to update jobs to ..
    run this code in either jenkins script console , or as i prefer, in form of init.groovy , so when jenkins amster starts, i create a user for JJb, after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_
    This is pretty simple snippet to get API Token of a user , lets say "MYUser" in jenkins.
    its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins,
    and you need to get the api token which JJB needs inorder to update jobs to ..
    run this code in either jenkins script console , or as i prefer, in form of init.groovy.
    so when jenkins amster starts, i create a user for JJb.
    after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

    ///////////////////////////////////////////////////////////////////////
    import jenkins.security.*
    //j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
  6. imranity created this gist Mar 19, 2015.
    11 changes: 11 additions & 0 deletions get-api-token-of-user-jenkins-groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    This is pretty simple snippet to get API Token of a user , lets say "MYUser" in jenkins , its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins, and you need to get the api token which JJB needs inorder to update jobs to ..
    run this code in either jenkins script console , or as i prefer, in form of init.groovy , so when jenkins amster starts, i create a user for JJb, after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_
    ///////////////////////////////////////////////////////////////////////
    import jenkins.security.*
    //j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    User u = User.get("Myuser")
    ApiTokenProperty t = u.getProperty(ApiTokenProperty.class)
    def token = t.getApiToken()
    //token.getClass()
    println "token is $token "
    ////////////////////////////////////////////////////////////////////////