2011-02-02 9 views
5

Tôi có một tập lệnh Python hoạt động trên Hudson được xây dựng và rất thích có thể thiết lập mô tả về bản dựng theo chương trình.Đặt Hudson Xây dựng Mô tả qua API Web

Tôi có thể nhấp vào "Thêm mô tả" trên trang của một công trình và điền vào biểu mẫu, làm cách nào để BẬT một số dữ liệu cho cùng một URL có biểu mẫu?

Trả lời

7

đặn nó ra, cần phải POST sau khi dữ liệu mẫu (kiểu nội dung application/x-www-form-urlencoded) để

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

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

Trong mã:

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) 
+2

Tôi đang sử dụng Jenkins và tôi nhận được 403 khi tôi dùng thử. Bất cứ ai biết nếu điều này vẫn còn hoạt động trong Jenkins? –

2

Sử dụng một 'Execute hệ thống Groovy tập lệnh 'Tạo tác vụ:

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

(sẽ nhận xét, nhưng không đủ đại diện)

Nhờ jtb cho phần lớn phương pháp tiếp cận này. Nếu an ninh được kích hoạt trên máy chủ, tôi thấy rằng tôi có thể xác thực sử dụng mã này (chuyển thể từ here)

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) 

Các giá trị cho người sử dụng và mã thông báo có thể được tìm thấy dưới API Mã trong: http://<myserver>/me/configure

0

Đây là lệnh curl làm việc tốt từ trình bao. Thay thế văn bản ở giữa và bao gồm {}.

curl -X POST -u {user: password} -H 'Loại nội dung: application/x-www-form-urlencoded' --data-urlencode description = {descriptionstring} {hudsonurl}/job/{jobname }/{buildnumber}/submitDescription