2017-04-20 157 views
1

我有一個內部網站,我正在爲我的公司開發,以便從Jenkins作業中觸發構建我們的移動應用程序。該網站是用AngularJS編寫的,我使用http模塊來調用Jenkins。Jenkins參數化構建觸發器,不帶參數

我在我的服務角度的方法是這樣的:

postBuildRequest : function(platform, project, ticket, environment, username, password, callback) 
    { 
    var method = 'GET'; 
    var url = "http://JENKINS_URL/JOB_NAME/buildWithParameters"; 
    var params = 
    { 
     token: "some_job_token", 
     parameter: [{ platform: platform, project: project, ticket: ticket, environment: environment }] 
    } 
    var headers = 
    { 
     "Authorization": "Basic " + window.btoa(username + ":" + password) 
    } 
    var config = 
    { 
     method: method, 
     url: url, 
     headers: headers, 
     params: params 
    }; 

    $http(config).then(
     function successCallback(response) { 
     console.log("postBuildRequest Success!! \n" + response.statusText + " with Status Code: " + response.status); 
     callback(response); 
     }, 
     function errorCallback(response) { 
     console.log("postBuildRequest Error :(\n" + response.statusText + " with Status Code: " + response.status); 
     callback(response); 
     } 
    ); 

    } 

我詹金斯作業具有以下參數設置:

enter image description here

的工作裏面我的生成命令看起來像這樣(殼):

# Parse the build variant 
if [$environment == 'live']; then 
    liveorstaging='--live' 
elif [$environment == 'staging']; then 
    liveorstaging='--staging' 
else 
    liveorstaging='' 
fi 

# Run the config buildandroid script 
if ! [ -z $ticket ]; then 
    config buildandroid $project -t $ticket $liveorstaging --commit 
else 
    config buildandroid $project --live --commit 
fi 

我可以觸發b很好,但它失敗了,因爲它沒有看到參數。

我的控制檯吐出:

12:44:39 Usage: config buildandroid [OPTIONS] PROJECT 
12:44:39 
12:44:39 Error: Missing argument "project". 
12:44:39 Build step 'Execute shell' marked build as failure 
12:44:39 Finished: FAILURE 

如果我看參數,它們是空的:

enter image description here

所以......我明明做錯事與我HTTP請求...任何想法?

+0

您的構建腳本包含語法錯誤 – jordanm

+0

這樣做嗎?該作業可以手動運行......(它最終失敗,因爲它調用的Python腳本存在問題......) –

+0

是的,您在環境檢查中缺少空白,但即使該問題已修復,if條件也不會永遠是真的,因爲你在比較靜態字符串('environment'應該是'$ environment')。 – jordanm

回答

1

那麼......我修好了。我意識到,我是在https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build字面意思服用維基頁面,張貼我所有的參數作爲

PARAMETER=[{key:value}] 

,我應該做的事情就像這樣:

var params = 
    { 
     token: token, 
     key1: value1, 
     key2: value2, 
     key3: value3, 
     key4: value4 
    } 

讓我的網址是這樣的:

buildWithParameters?environment=staging&platform=some_platform&project=some_project&ticket=some_ticket&token=eb_some_token