Automate PhoneGap Build help
danielem18727002 Jan 20, 2017 9:18 AMHi,
I am new at the PhoneGap API and I am trying to automate the build process of the App I am working on.
I have a local zip file which I would like upload to phonegap build, make a build and download it on my laptop! I have got something in place but at the moment I cannot managed to:
- download the apk/ios file into my laptop
- listen for when the build is ready to download
I am using Gulp tasks for the automation and this is what I have got so far:
var pgBuild = require('phonegap-build-api');
gulp.task('build-debug', function () {
//ask for authentication
pgBuild.auth({ username: 'myemail@gmail.com', password: 'mypassword' }, function (e, api) {
api.get(phonegapEndpoint, function(e, data) {
var options = {
form: {
data: {
platforms: [ 'ios', 'android' ],
download: './BuildOutputs/',
debug: true
},
file: './www/app.zip'
}
};
//make the build
api.post('/apps/myappid/build', options, function(e, data) {
if(data != null) {
if(data.status.android === "complete") {
//here I should have my build saved in the path mentioned on form.data.download' which is in 'BuildOutputs' folder
}
}
});
}
This is what the 'data' attribute looks like after the build:
build_data = {
id: myappid,
title: 'MyApp',
package: 'xx.xxxxxxx.xx',
version: '3.0.13',
build_count: 297,
private: true,
phonegap_version: 'cli-6.4.0',
hydrates: false,
share: false,
last_build: '2017-01-19 07:51:48 -0800',
description: 'Electronic based rota and timesheet.',
repo: null,
tag: null,
debug: false,
head: null,
link: '/api/v1/apps/myappid',
plugins: '/api/v1/apps/myappid/plugins',
completed: false,
role: 'admin',
icon: {
filename: null,
link: null
},
status: {
android: 'complete',
ios: 'pending',
winphone: 'error'
},
phonegap_versions: {
android: '6.1.0',
ios: '4.3.0',
winphone: '4.4.3'
},
download: {
android: '/api/v1/apps/myappid/android'
},
error: {
winphone: '"["/home/Administrator/gimlet/var/winphone8/4.4.3/bin/create.bat ./project xxxxxx"]": No such file or directory - /home/Administrator/gimlet/var/winphone8/4.4.3/bin/create.bat'
},
install_url: 'https://build.phonegap.com/apps/myappid/install/sxGWtXktrxvm92yesPt4',
share_url: 'https://build.phonegap.com/apps/myappid/share',
collaborators: {
link: '/api/v1/apps/myappid/collaborators',
active: [
[
Object
],
[
Object
]
],
pending: []
},
keys: {
android: {
id: myandroidid,
title: 'Android',
platform: 'android',
link: '/api/v1/keys/android/myandroidid',
default: false
},
ios: {
id: myiosid,
title: 'iOS Release Distr',
platform: 'ios',
link: '/api/v1/keys/ios/myiosid',
default: false
},
winphone: null
},
logs: {
android: '/api/v1/apps/myappid/logs/android/build',
ios: '/api/v1/apps/myappid/logs/ios/build',
winphone: '/api/v1/apps/myappid/logs/winphone/build'
}
};
Now if I look at the download attribute it says:
download: {
android: '/api/v1/apps/myappid/android'
}
I would have expect the APK to be saved where I wanted to but it's not. Does anyone know how to do that?
Another question would be about 'listen' for the pending builds to be completed, well in the API Documentation I have found this:
"Once the builds are queued, you will want to watch the results of GET /api/v1/apps/:id
to check when each platform's status changes from pending
to either complete
or error
." but I am not able to do it
Can anyone help please?
Thanks