LoginSignup
2
3

More than 5 years have passed since last update.

AWS Lambdaを使ってCircleCIのビルドを実行する

Last updated at Posted at 2016-02-16

初心者が試しにやってるようなものなので、間違えている部分があったらコメントで教えていただけると大変うれしいです :bow:


基本は[lambda] [middleman] [wercker] 静的ビルドサイトに足りない機能をLambdaで補ってみる - 予約投稿編 | 株式会社フーディソン エンジニアブログを参考にしつつ、AWS LambdaからCircleCIのAPIを叩き新しくビルドを実行させるようにしてみた。

参考記事の"3, 記事の予約投稿"のセクションでLambdaを使いwerckerのAPIを叩いているが、そのコードを参考にしつつCircleCI用に書きなおした。

ここで叩いているのはTrigger a new Build(CircleCIのドキュメント)。

var http = require('https');

// Valiables
var circleci_api_token = "<YOUR_CIRCLECI_API_TOKEN>";
var post_data = {};
var post_options = {
  hostname: 'circleci.com',
  port:     443,
  path:     '/api/v1/project/:username/:project/tree/:branch?circle-token=' + circleci_api_token,
  method:   'POST',
  headers: {
    'Content-Type':   'application/json'
  }
};

exports.handler = function(event, context) {
  // Set up the request
  var post_req = http.request(post_options, function(res) {
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
          console.log('Response: ' + chunk);
          context.succeed();
      });
  });

  // Post the data
  post_req.write(JSON.stringify(post_data));
  post_req.end();
};

circleci_api_token のところとpathの中身を適宜書き換える必要がある。
CircleCIのAPIトークンはAccount - CircleCIで取得する。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3