Running a script conditionally doesn't work in travis.yml, why?

The following reasons do not allow building at all. When I try to check the file travis.yml, it complains that the line just above the if statement is missing a character -in column 3, but the error is related to the if statement below.

Do I need to move the if statement to a script?

# Deploy
after_success:
  - ./tools/docker-push-container.sh
  - if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then
      ./.travis/success_message.sh
    fi
+4
source share
3 answers

You make some assumptions about the YAML syntax that cause problems. If you “highlight” the YAML line by inserting the following lines into it, for example:

- The quick brown fox
  jumped over the
  lazy dog.

This is exactly the same as you wrote this:

- The quick brown fox jumped over the lazy dog.

This means that your shell fragment that you wrote as:

  - if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then
      ./.travis/success_message.sh
    fi

It actually becomes:

if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then ./.travis/success_message.sh fi

, :

sh: -c: line 1: syntax error: unexpected end of file

script YAML, |, :

  - |
    if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then
      ./.travis/success_message.sh
    fi

, , :

if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then
  ./.travis/success_message.sh
fi

:

  - if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then
      ./.travis/success_message.sh;
    fi

; fi. :

if [ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]; then ./.travis/success_message.sh; fi

... .

+10

larsks, , , bash, && ||, .

( )

  - if [ $TRAVIS_PULL_REQUEST == false && $TRAVIS_BRANCH == "development" ]; then
        echo "# Bump version and flyway migrate db"; 
    else 
        echo "Skip version increment!"; 
    fi

.travis.yml Travis Lint, , , bash, , , SO ,

    - if [ $TRAVIS_PULL_REQUEST == false ] && [ $TRAVIS_BRANCH == "development" ]; then
            echo "# Bump version and flyway migrate db"; 
        else 
            echo "Skip version increment!"; 
        fi

. , && || bash. , - .

0

, :

  • [[( "$ TRAVIS_OS_NAME" == "osx" ) && & && ( "$ TOXENV" == "py36" )]]; brew ;
0

Source: https://habr.com/ru/post/1650302/


All Articles