El script de Shell se valida en línea, no funciona en Travis CI (token fi inesperado)
Frecuentes
Visto 303 equipos
1
I have the following shell script that gets validated online, but fails on Travis CI:
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
if [ "$TRAVIS_BRANCH" == "master" ]; then
# define some variables
GH_USER=skiwi2
GH_REPO=TCG
# get info about all releases
echo -e "Getting info about previous releases"
curl -X GET -H "Authorization: token ${GH_TOKEN}" \
"https://api.github.com/repos/${GH_USER}/${GH_REPO}/releases" > json.txt
# extract info only about only "latest-release" tag
cat json.txt |jq 'map(select (.tag_name == "latest-master"))' > latest.txt
# get id of release
ID_TO_DELETE=`cat latest.txt |jq '.[0].id'`
# delete previous release
echo -e "Deleting release number ${ID_TO_DELETE}"
curl -X DELETE -H "Authorization: token ${GH_TOKEN}" \
"https://api.github.com/repos/${GH_USER}/${GH_REPO}/releases/${ID_TO_DELETE}"
# delete previous tag
curl -X DELETE -H "Authorization: token ${GH_TOKEN}" \
"https://api.github.com/repos/${GH_USER}/${GH_REPO}/git/refs/tags/latest-master"
echo -e "Creating a release\n"
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
-d '{"tag_name": "latest-master", "target_commitish": "master", "name": "master-${TRAVIS_BUILD_NUMBER}", "body": "Automatic release based on latest commit to master branch generated by Travis CI.", "draft": false, "prerelease": true}' "https://api.github.com/repos/${GH_USER}/${GH_REPO}/releases" > json.txt
IDDI=`cat json.txt | jq '.id'`
echo -e "Uploading JAR\n"
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/java-archive" \
--data-binary /home/travis/build/{$GH_USER}/{$GH_REPO}/target/TCG-1.0-SNAPSHOT.jar \
"https://uploads.github.com/repos/${GH_USER}/${GH_REPO}/releases/${IDDI}/assets?name=tcg-master-${TRAVIS_BUILD_NUMBER}.jar"
echo -e "Done uploading\n"
fi
fi
Falla con:
./upload_binaries.sh: line 44: syntax error near unexpected token `fi'
./upload_binaries.sh: line 44: `fi'
However to my knowledge this should not be unexpected. Unfortunately I am not too experienced with shell, can it be that older versions required a different syntax?
Line 44 is the very last line of the script, the one containing the last fi
.
Moreover, all variables that are not defined in this script, are being defined in some other way by the Travis CI.
1 Respuestas
0
Intente . equal sign for test.
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
if [ "$TRAVIS_BRANCH" = "master" ]; then
...
On man page for test we can read:
string1 = string2 True if the strings string1 and string2 are identical.
Respondido 28 Feb 15, 14:02
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas shell travis-ci or haz tu propia pregunta.
Intenta reemplazar
--data-binary /home/travis/build/{$GH_USER}/{$GH_REPO}/target/TCG-1.0-SNAPSHOT.jar \
--data-binary "/home/travis/build/{$GH_USER}/{$GH_REPO}/target/TCG-1.0-SNAPSHOT.jar" \
- Gergo ErdosiAlso, it should
${GH_USER}
no{$GH_USER}
. Lo mismo con{$GH_REPO}
. - Gergo ErdosiEso es mucho inútil
cat
s - tripleeeDoes your script lack a proper línea shebang? - tripleee
I have used another existing script as a huge inspiration source and that one (judging by the github releases) seems to be working properly there. I'll incorporate all changes suggested here though. - skiwi