Skip to content

Latest commit

 

History

History

jenkins-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Jenkins HTTP API experiment

Some links:

Jenkins and security with CSRF protection

USER=admin
APITOKEN=8861882a9bfae61392edf23c402359cc  ## API Token section of http://localhost:8080/user/admin/configure
SERVER=http://localhost:8080
CRUMB=$(curl --user $USER:$APITOKEN \
    $SERVER/crumbIssuer/api/xml?xpath=concat\(//crumbRequestField,%22:%22,//crumb\))
echo $CRUMB

Jenkins and views

## update view
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST --data-binary @sample-view.xml -H "Content-Type:text/xml" $SERVER/view/sds/config.xml

## add / remove job to/from view view
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST $SERVER/view/sds/addJobToView?name=test_job_v3
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST $SERVER/view/sds/removeJobFromView?name=test_job_v3

## create view
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST -d @sample-view.xml -H "Content-Type: text/xml" $SERVER/createView?name=MyView

sample-view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<hudson.model.ListView>
  <name>sds</name>
  <description>foooooo</description>
  <filterExecutors>false</filterExecutors>
  <filterQueue>false</filterQueue>
  <properties class="hudson.model.View$PropertyList"/>
  <jobNames>
    <comparator class="hudson.util.CaseInsensitiveComparator"/>
    <string>test_job</string>
    <string>test_job_v2</string>
  </jobNames>
  <jobFilters/>
  <columns>
    <hudson.views.StatusColumn/>
    <hudson.views.WeatherColumn/>
    <hudson.views.JobColumn/>
    <hudson.views.LastSuccessColumn/>
    <hudson.views.LastFailureColumn/>
    <hudson.views.LastDurationColumn/>
    <hudson.views.BuildButtonColumn/>
    <hudson.plugins.favorite.column.FavoriteColumn plugin="[email protected]"/>
  </columns>
  <recurse>false</recurse>
</hudson.model.ListView>

Jenkins and folders

## check if job / folder is available
curl --user $USER:$APITOKEN -H "$CRUMB" -X GET $SERVER/checkJobName?value=a-class-folder
curl --user $USER:$APITOKEN -H "$CRUMB" -X GET $SERVER/checkJobName?value=test_job_v3

## create folder
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST "$SERVER/createItem?name=rs-folder-experiment&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22rs-folder-experiment%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK" -H "Content-Type:application/x-www-form-urlencoded"

## create job in folder
curl --user $USER:$APITOKEN -H "$CRUMB" $SERVER/job/test_job/config.xml > sample-job.xml
curl --user $USER:$APITOKEN -H "$CRUMB" -X POST --data-binary @sample-job.xml -H "Content-Type:text/xml" $SERVER/job/rs-folder-experiment/createItem?name=test_job_in_folder

Jenkins Job Builder and folders

JJB master has some activity related to folders, not yet available in tagged version of JJB.

Basic folder support + Cloudbees folder creation support