Hello, I'm attempting to trigger a bitbucket pipeline from a lambda function and I'm getting a 400 error when I submit the build to the pipeline.
Here is the code for the lambda function, I redacted some parts of the code with <username>, <password>, and <slug>:
'use strict';
const https = require('https');
exports.handler = (event, context, callback) => {
console.log("event:", event );
let body = JSON.stringify({
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "develop"
}
});
let auth = 'Basic ' + new Buffer('<username>:<password>').toString('base64');
let options = {
hostname: 'api.bitbucket.org',
path: '2.0/repositories/<username>/<slug>/pipelines/',
method: 'POST',
headers: {
"Content-Type": "application/json",
"Content-Length": body.length,
"Authorization": auth
}
};
//console.log(`request:`, options );
const req = https.request( options, (res) => {
console.log(`statusCode: ${res.statusCode}, headers:`, res.headers);
res.on('data', (d) => {
let resp = d.toString();
console.log("data:", resp );
const response = {
statusCode: res.statusCode,
body: resp
};
callback(null, response);
});
});
req.on('error', (e) => {
console.error(e);
const response = {
statusCode: 500,
body: JSON.stringify({ error: e.message } )
};
callback(null, response);
});
//console.log("body:", body );
req.write(body);
req.end();
};
When I test the lambda, I get the following response:
2018-09-15T02:41:52.458Z e6dfd4b4-b890-11e8-9be5-9ff563700397 statusCode: 400, headers: { server: 'nginx',
'content-type': 'text/html',
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
date: 'Sat, 15 Sep 2018 02:41:52 GMT',
connection: 'close',
'content-length': '166' }
2018-09-15T02:41:52.459Z e6dfd4b4-b890-11e8-9be5-9ff563700397 data: <html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
I've re-read the docs several times so far and I'm at a loss as to why it thinks my request is bad.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.