Shell脚本在线验证,不适用于Travis CI(意外令牌fi)

时间:2014-05-24 15:27:36

标签: shell travis-ci

我有以下在线验证的shell脚本,但在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

失败了:

./upload_binaries.sh: line 44: syntax error near unexpected token `fi'
./upload_binaries.sh: line 44: `fi'

但据我所知,这不应该是意料之外的。不幸的是我对shell不太熟悉,旧版本是否需要不同的语法?

第44行是脚本的最后一行,包含最后一行fi

此外,Travis CI正在以其他方式定义此脚本中未定义的所有变量。

1 个答案:

答案 0 :(得分:0)

尝试使用一个等号进行测试。

if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
if [ "$TRAVIS_BRANCH" = "master" ]; then
...

在测试手册页上我们可以阅读:

 string1 = string2           True if the strings string1 and string2 are identical.