Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use curl in Travis-CI config file (YAML)?

Ok. This is slowly driving me crazy. I have set up CI on Travis for one of my projects. I'm running some JUnit tests and I would like to upload the tests results to my own server, so it's much easier to browse them.

Basically, all I want do is to call this:

curl -H 'Authorization: Token someToken' -X POST http://my.server.com -F [email protected]

So this is what I'm trying to do in .travis.yml file.

after_script:
 - curl -H 'Authorization: Token someToken' -X POST http://my.server.com -F [email protected]

The problem is that for the line above I'm getting an error which looks like this:

$ {:"curl -H '\"Authorization"=>"Token someToken\"' -X POST http://my.server.com -F [email protected]"}
/home/travis/build.sh: line 45: Token someToken"' -X POST http://my.server.com -F [email protected]}: No such file or directory

I've learned that in YAML colon represents a pair of key-value and I've found out that one can just use the quotes to escape the colon.

Well - this is the place where I am stuck. I tried to apply those quotes in many different ways but somehow each time I keep getting the same error all over again.

For example:

curl -H '"Authorization: Token someToken"'
curl -H "\"Authorization: Token someToken\""
curl -H "'Authorization: Token someToken'"
curl -H '"Authorization": Token someToken'

I feel like being stupid and I know that the fix for this is probably a simple thing, but I've felt into that "escape quotes while escaping quotes" thing and if anyone could just point me in the right direction, I would be really grateful.

I'm also linking to those questions as I tried to follow them to solve my problem:

Escaping colons in YAML

How to escape indicator characters (i.e. : or - ) in YAML

like image 617
scana Avatar asked Jan 08 '16 23:01

scana


2 Answers

In YAML, colons are delimiters that separate map keys and values.

What you have now:

curl -H 'Authorization: token someToken' "https://api.github.com/repos/:owner/:repo/releases/tags/$TRAVIS_TAG"

​ is a map with key curl -H 'Authorization and value token someToken' "https://api.github.com/repos/:owner/:repo/releases/tags/$TRAVIS_TAG". You can see how this creeps into the build script.

What you want is a properly quoted string:

after_deploy:
  - "curl -H 'Authorization: token someToken' \"https://api.github.com/repos/:owner/:repo/releases/tags/$TRAVIS_TAG\""
like image 73
banzaiman Avatar answered Nov 19 '22 08:11

banzaiman


Ok - I've managed to solve (or hack) this problem, by creating simple bash script:

#!/bin/bash
curl -H 'Authorization: Token someToken' -X POST http://my.server.com -F [email protected]

And then I proceed to call the script in .travis.yml file:

- ./upload_script.sh

All credits goes to @набиячлэвэлиь for suggesting me that solution in the comments.

Any other - nicer - solutions are more than welcome.

like image 43
scana Avatar answered Nov 19 '22 08:11

scana