Set Hudson build description via web API

I have a Python script that works with Hudson assemblies and would like to be able to set the assembly description programmatically.

I can click "Add Description" on the assembly page and fill out the form, how can I send POST some data to the same URL as the form?

+5
source share
4 answers

It turned out, you need to send the following form data (content type application/x-www-form-urlencoded) to POST in

http: // myserver / hudson / job / thebuild / 10 / submitDescription

{"description": "Some Description for the build"}

In code:

def set_description(build_url, desc):
    req_data = urllib.urlencode({'description': desc})
    req = urllib2.Request(build_url + '/submitDescription', req_data)
    req.add_header('Content-Type', 'application/x-www-form-urlencoded')
    urllib2.urlopen(req)
+7
source

Using the 'Execute system Groovy script' Build task:

import hudson.model.Cause
import hudson.model.Job
import jenkins.model.Jenkins

final JOB_NAME = 'my-job-name'

final jenkins = Jenkins.instance
final job = jenkins.getItemByFullName(JOB_NAME, Job.class)
final currentBuild = Thread.currentThread().executable
final buildNumber = currentBuild.getNumber()

job.builds
    .findAll { build ->
        build.number == buildNumber
    }
    .each { build ->
        build.setDescription("Some Description for the build")
    }
+2
source

( , rep)

jtb . , , ( )

def set_description(build_url, desc, user, token):
    import base64, urllib, urllib2
    req_data = urllib.urlencode( {'description': desc } )
    req = urllib2.Request(build_url + '/submitDescription', req_data)
    req.add_header('Content-Type', 'application/x-www-form-urlencoded')
    auth = 'Basic {}'.format(base64.b64encode("{}:{}".format( user, token )))
    req.add_header( 'Authorization', auth )
    response = urllib2.urlopen(req)

API Token : http://<myserver>/me/configure

+2

curl, . {}.

curl -X POST -u {user: password} -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode description = {descriptionstring} {hudsonurl}/job/{jobname}/{BuildNumber}/submitDescription

0

All Articles