Add design information to Jenkins using REST

Does anyone know how to add assembly information to an existing Jenkins assembly?

What I'm trying to do is replace the build number 1 with the actual full version number that the assembly represents. I can do this manually by going to http: // MyJenkinsServer / job / [event_name] / [buildnumber] / configure

I tried redesigning the headers using chrome, seeing what it sends to the server, and found the following:

Request URL:http://<server>/job/test_job/1/configSubmit
Request Method:POST
Status Code:200 OK

Request Headers view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:192
Content-Type:application/x-www-form-urlencoded
Cookie:hudson_auto_refresh=false; JSESSIONID=qbn3q22phkbc12f1ikk0ssijb; screenResolution=1920x1200
Referer:http://<server>/job/test_job/1/configure
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4

Form Data view URL encoded
displayName:#1
description:test4
core:apply:true
json:{"displayName": "#1", "description": "test4", "": "test4", "core:apply": "true"}**

Response Headers view source
Content-Length:155
Content-Type:text/html;charset=UTF-8
Server:Jetty(8.y.z-SNAPSHOT)

This at least gives me the form options that I need for POST. So from this, I came up with the following python3 code:

import requests
params={"displayName":"Hello World",
    "description":"This is my description",
    "":"This is my description",
    "core:apply":"true"}

a = requests.post("http://myjenkinsserver/job/test_jira_job_update/1/configSubmit", data=params, auth=( username, pwd), headers={"content-type":"text/html;charset=UTF-8"} )
if a.raw.status != 200:
    print("***ERROR***")
    print(a.raw.status)
    print(a.raw.reason)

but unfortunately this happened with the following error:

***ERROR***
400
Nothing is submitted

Any ideas what I'm doing wrong? Is my approach to this problem completely wrong?

+3
source
4

, . json POST:

p = {'json': '{"displayName":"New Name", "description":"New Description"}'}
requests.post('http://jenkins:8080/job/jobname/5/configSubmit', data=p, auth=(user, token))

, Jenkins 1.517.

( , , , .)

+3

( Google), . , , ...

import json
import requests

job_name = "my-jenkins-job"
job_parameters = [
    {
        "name": "ip_address",
        "value": "192.168..."
    },
    {
        "name": "url",
        "value": "http://..."
    },
    {
        "name": "architecture",
        "value": "x86"
    }
]

data = {"json": json.dumps({"parameter": build_parameters})}
r = requests.post('http://<jenkins server>/job/{job_name}/build/api/json'.format(job_name=job_name), data=data)
r.raise_for_status()
+1

Try listing a tuple instead of a dictionary and urlencode.

params=[("displayName","Hello World"),
    ("description","This is my description")]
dataParam = urllib.urlencode(params)
0
source

The list of options has changed. Also, make sure that you have the same number of keys defined in the Jenkins user interface. If not 400 or 500!

param = {"parameter": [{"name": "CustomerName", "value": "AcmeCorp"}]}
data = {"json": json.dumps(param)}
headers["content-type"] = "application/x-www-form-urlencoded"
.
.
.
r = requests.post(jobURL, headers = headers, data=data)
0
source

All Articles