关于angularjs:Jenkins不带参数的参数化生成触发

Jenkins parameterized build triggering with no parameters

我有一个内部网站正在为我的公司开发,目的是从Jenkins的工作中触发我们的移动应用程序的构建。该网站是用AngularJS编写的,我正在使用http模块来调用Jenkins。

我在服务中使用的angular方法如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  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!! \
" + response.statusText +" with Status Code:" + response.status);
        callback(response);
      },
      function errorCallback(response) {
        console.log("postBuildRequest Error :( \
" + response.statusText +" with Status Code:" + response.status);
        callback(response);
      }
    );

  }

我的Jenkins作业具有以下参数设置:

enter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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

我可以正常触发构建,但是失败了,因为它看不到参数。

我的控制台吐出来了:

1
2
3
4
5
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


好吧...我修好了。我意识到我正在访问位于https://wiki.jenkins-ci.org/display/JENKINS/Parameterized Build的Wiki页面,并且将我的所有参数都发布为

1
PARAMETER=[{key:value}]

我应该在这样的地方做:

1
2
3
4
5
6
7
8
  var params =
    {
      token: token,
      key1: value1,
      key2: value2,
      key3: value3,
      key4: value4
    }

这样我的网址看起来像:

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