我正在为我的公司开发一个内部网站,以便从Jenkins工作中触发我们的移动应用程序的构建。该网站是用AngularJS编写的,我使用http模块来调用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);
}
);
}
我的Jenkins作业设置了以下参数:
我在工作中的构建命令看起来像这样(shell):
# 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
我可以触发构建很好,但它失败了,因为它没有看到参数。
我的控制台正在吐出:
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
如果我查看参数,它们就是空的:
所以......我的HTTP请求显然有问题......有什么想法吗?
答案 0 :(得分:1)
嗯......我修好了。我意识到我正在https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build以非常字面的方式访问Wiki页面并将所有参数发布为
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