Search code examples
amazon-web-servicescontinuous-integrationazure-devopsbuild-definitionaws-device-farm

How to use output of one command as an input to another on VSTS CI


I'm trying to set up CI on Microsoft's Visual Studio Team Services (VSTS) that includes AWS CLI task. I have some steps for building an iOS app and those steps are successfully executed. Then, I want to upload generated .ipa files to AWS Device Farm using AWS CLI commands.

To upload files to AWS, I followed this documentation, where it is stated that I have to run aws devicefarm create-upload ... command first. This command is executed successfully on VSTS and it outputs JSON formatted response, like this:

{
    "upload": {
        "arn": "arn:aws:devicefarm:us-west-2:123456789012:upload:070fc3ca-7ec1-4741-9c1f-d3e044efc506/dd72723a-ae9e-4087-09e6-f4cea3599514",
        "name": "MyAppiOSUITests_20180309.3.ipa",
        "created": 1520601466.978,
        "type": "IOS_APP",
        "status": "INITIALIZED",
        "url": "https://prod-us-west-2-uploads.s3-us-west-2.amazonaws.com/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A123456789012%3Aproject%3A070fc3ca-c7e1-4471-91cf-d3e4efc50604/uploads/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A123456789012%3Aupload%3A070fc3ca-7ec1-4741-9c1f-d3e044efc506/dd72723a-ae9e-4087-09e6-f4cea3599514/app.apk?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20170824T224008Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86400&X-Amz-Credential=AKIAEXAMPLEPBUMBC3GA%2F20170824%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=05050370c38894ef5bd09f5d009f36fc8f96fa4bb04e1bba9aca71b8dbe49a0f"
    }
}

This basically means that this command just prepares upload and to upload real file, I have to do HTTP PUT afterwards (using curl as suggested).

In that JSON response I get url object whose value is a URL that I have to send HTTP POST request with the file I want to upload, like this:

curl -T MyAppiOSUITests_20180309.3.ipa "https://prod-us-west-2-uploads.s3-us-west-2.amazonaws.com/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A123456789012%3Aproject%3A070fc3ca-c7e1-4471-91cf-d3e4efc50604/uploads/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A123456789012%3Aupload%3A070fc3ca-7ec1-4741-9c1f-d3e044efc506/dd72723a-ae9e-4087-09e6-f4cea3599514/app.apk?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20170824T224008Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86400&X-Amz-Credential=AKIAEXAMPLEPBUMBC3GA%2F20170824%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=05050370c38894ef5bd09f5d009f36fc8f96fa4bb04e1bba9aca71b8dbe49a0f"

Problem is that I have to use two tasks (aws and curl) to upload single file, where the second one depends on the output of the first one. How can I save output between VSTS build tasks (and parse it to get just value of url object) and pass that output to another task? Or, can I avoid using curl and just use aws tool with single command to upload file to Device Farm?

Note: I'm using Mac powered agent that is connected to VSTS, so all of these commands are executed on OS X.


Solution

  • Hello I'm not overly familiar with VSTS, but I see you're using a mac, so if you want a full BASH implementation you could do something like.

    var=$(cat file.txt | jq -r '.upload.url')
    curl -T TEST.ipa $var