Use import in .travis.yml does not trigger build

Hi, I have a fairly big .travis.yml that I want to separate in different files, specificaly the before_install parts.

I found the new functionality of import syntax that I thought corresponds to this use case, though I do not manage to use it, the build is not triggered after my push.

I have activated Build Config Validation feature and tested also with version: ~> 1.0.

I thought I could write like this, do you think there’s mistake in my code or in my understanding?

before_install:
 
import: 
  - ./src/test/resources/docker/build.yml
  - ./src/test/resources/docker/run.yml
  - ./src/test/resources/docker/config.yml

script: mvn clean verify sonar:sonar
  
import: ./src/test/resources/docker/metrics.yml

Thanks

Is it intended that you have two import keys?

Yes, I would want to import 3 docker relative parts into before_install and one docker relative part into script, respectively build, run, config, then metrics.

The working single .yml file is like this

before_install:
  
  - export MAVEN_OPTS="-Xms512m -Xmx3g -XX:PermSize=256m $MAVEN_OPTS"
    
  # Docker configuration
  - docker build -t mysql 
    -f src/test/resources/docker/Dockerfile.mysql .
    
  - docker build -t mysql 
    -f src/test/resources/docker/Dockerfile.mysql-5.5.40 .
    
  - docker build -t postgres 
    -f src/test/resources/docker/Dockerfile.postgres .
    
  - docker build -t sqlserver 
    -f src/test/resources/docker/Dockerfile.sqlserver .
    
  - docker run --name jsql-mysql  
    --publish 3306:3306 
    -e MYSQL_ROOT_PASSWORD=my-secret-pw 
    -d mysql
    
  - docker run --name jsql-mysql-5.5.40 
    --publish 3307:3306 
    -e MYSQL_ROOT_PASSWORD=my-secret-pw 
    -d mysql:5.5.40
    
  - docker run --name jsql-postgres 
    --publish 5432:5432 
    -e POSTGRES_PASSWORD=my-secret-pw 
    -d postgres 
    -c 'shared_buffers=256MB'
    -c 'max_connections=1000'
    
  - docker run --name jsql-sqlserver 
    --publish 1434:1434 
    --publish 1433:1433 
    -e "ACCEPT_EULA=Y" 
    -e "SA_PASSWORD=yourStrong(!)Password"
    -u 0:0
    -d sqlserver 
    
  - docker images && docker ps && pwd
  
  # Buff MySQL
  - docker exec -it jsql-mysql /bin/bash
    -c "
       mysql -uroot -pmy-secret-pw -e '
       SET GLOBAL max_connections = 100000;
       SET GLOBAL thread_cache_size = 16384;
       SET GLOBAL table_open_cache = 524288;
       ';
       "

  # Check MySQL status
  - docker exec -it jsql-mysql /bin/bash
    -c "
       mysql -uroot -pmy-secret-pw -e '
       SHOW GLOBAL variables WHERE Variable_name RLIKE \"thread_cache_size|^max_connections|table_open_cache\";
       SHOW GLOBAL status WHERE Variable_name RLIKE \"Threads_cached|Max_used_connections|Threads_created|Connections|Opened_tables|Threads_connected|Threads_running|^Queries\"
       ';
       "

  # Check Postgres status
  - docker exec -it jsql-postgres /bin/bash
    -c "
       export PGPASSWORD=my-secret-pw;
       psql -U postgres -h 127.0.0.1 -d \"\" -e -a -c '
       show max_connections;
       ';
       "
       
  - sleep 10s
  - sudo docker exec -it jsql-sqlserver /opt/mssql-tools/bin/sqlcmd -S "tcp:127.0.0.1,1434" -U SA -P "yourStrong(!)Password" -Q "select @@version"


script:

  - mvn clean verify sonar:sonar
  
  # Check MySQL status
  - docker exec -it jsql-mysql /bin/bash
    -c "
       mysql -uroot -pmy-secret-pw -e '
       SHOW GLOBAL status WHERE Variable_name RLIKE \"Threads_cached|Max_used_connections|Threads_created|Connections|Opened_tables|Threads_connected|Threads_running|^Queries\"
       ';
       "

It’s not entirely clear to me why, but https://travis-ci.org/github/ron190/jsql-injection/requests shows that we were unable to import metrics.yml.

Ok, I didn’t know the Requests panel, I see the error now :smile:, but I can’t figure out what’s different in file metrics.yml than it is in the three other ones.

I’d start with combining the two import keys. It’s definitely unnatural.

I replaced completely the 2nd import with a .sh, because I have to check dockerized databases metrics after integration tests.

before_install:
  - export MAVEN_OPTS="-Xms512m -Xmx3g -XX:PermSize=256m $MAVEN_OPTS"
  
import: 
  - src/test/resources/docker/build.yml
  - src/test/resources/docker/run.yml
  - src/test/resources/docker/config.yml

script:
  - mvn clean verify sonar:
  - ./src/test/resources/docker/metrics.sh

Now strangely enough it fails on previous single import bloc with error:

Could not parse ron190/jsql-injection:src/test/resources/docker/build.yml@766935975b8df2e6

Then I tried to just use .sh with Git executable rights and it works, but parsing in .yml is cleaner without the sh horrible syntax:

before_install:     
  - ./src/test/resources/docker/build.sh
  - ./src/test/resources/docker/run.sh
  - ./src/test/resources/docker/config.sh

script:
  - mvn clean verify sonar:
  - ./src/test/resources/docker/metrics.sh

With awful .sh :

REM Buff MySQL
docker exec -it jsql-mysql /bin/bash\
-c "\
   mysql -uroot -pmy-secret-pw -e '\
   SET GLOBAL max_connections = 100000;\
   SET GLOBAL thread_cache_size = 16384;\
   SET GLOBAL table_open_cache = 524288;\
   ';\
   "

I’m thinking… the structure of your previous YAML files are wrong (it was a simple array); it was a fragment, whereas we expect to find complete YAML file that confirm to our specifications and perform merges and what not to construct the configuration.

Yes, I guess now the purpose of import is to include nearly complete valid .yml definition rather than just a fragment.

Even if we see some mixed example, taken from the blog post:

Like :
https://github.com/ljharb/es-abstract/blob/master/.travis.yml
Or:

I was figuring that YAML was a fairly simple string tree, but I’m missing some notions described in the documentation to understand completely what’s happening:

sections (keys) that hold maps (hashes), and concatenates sequences (arrays)

Thank you anyway for your support :+1:

Did you end up resolving this issue, because I ran into something similar. In my main repo’s yml, I’m trying to import a yml from a submodule, but when I commit to my main repo, a build doesn’t trigger. In the requests tab, it shows the request was received and build created successfully, but no build is actually created. In the main repo’s yml, if I don’t specify version: ~> 1.0, then a build is successfully created but the import command has no effect. If I do specify version to enable the beta feature, no build is created.