How to perform install only once under multiple stages? - travis-ci

I want to avoid perform install process times under multiple stages. My travis-ci config as follow, how to avoid run install process both in test and deploy stage? Beacause install is time-cost.
os: linux
language: android
licenses:
- android-sdk-preview-license-.+
- android-sdk-license-.+
- google-gdk-license-.+
android:
components:
- tools
- platform-tools
- build-tools-28.0.3
- android-28
jdk: oraclejdk8
sudo: false
install:
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
- export PATH=$PATH:./flutter/bin
- flutter doctor
cache:
directories:
- "$HOME/.pub-cache"
stages:
- test
- name: depoly
if: tag =~ /^release-v\d+\.\d+\.\d+/ # tag match: release-v1.0.0
jobs:
include:
- stage: test
- script: flutter analyze lib/ test/
- script: flutter test test/
- stage: depoly
- script: flutter build apk
deploy:
provider: releases
api_key:
secure: $github_deploy_api_key
file: $APK_NAME
skip_cleanup: true
overwrite: true
on:
repo: stefanJi/Flutter4GitLab
branch: master

Related

You must be connected to the internet the first time you use the Grails wrapper

I have a setup that used to work for at least a couple of years without any issues. In my latest update, all of a sudden I am getting the following error:
#!/bin/bash -eo pipefail
./grailsw compile
You must be connected to the internet the first time you use the Grails wrapper
org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 3; The element type "hr" must be terminated by the matching end-tag "</hr>".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1473)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1749)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at grails.init.Start.getVersion(Start.java:36)
at grails.init.Start.main(Start.java:83)
Exited with code exit status 1
CircleCI received exit code 1
And basically, I am getting the same error for any grailsw command.
Here is my config file:
version: 2.0
references:
defaults: &defaults
docker:
- image: circleci/openjdk:8-jdk
working_directory: ~/priz-be
remote_docker: &remote_docker
setup_remote_docker:
docker_layer_caching: false
assemble_prod: &assemble_prod
run:
name: Assemble
command: ./gradlew -Dgrails.env=prod assemble
build_and_push_docker_image: &build_and_push_docker_image
run:
name: Build docker image
command: |
sudo apt-get update --fix-missing
sudo apt-get install python-pip python-dev
sudo pip install awscli
cp -p build/libs/priz-be-0.1.war docker/app.war
aws ecr get-login --no-include-email --region us-west-2 | sh
docker build -t priz-be docker
docker tag priz-be:latest 922556357703.dkr.ecr.us-west-2.amazonaws.com/priz-be:prod-$CIRCLE_SHA1
docker push 922556357703.dkr.ecr.us-west-2.amazonaws.com/priz-be:prod-$CIRCLE_SHA1
jobs:
checkout_code:
<<: *defaults
steps:
- checkout
- run:
name: Show current branch
command: echo ${CIRCLE_BRANCH}
- save_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/priz-be
compile:
<<: *defaults
steps:
- restore_cache:
keys:
- v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Compile the project
command: ./grailsw compile
# Cache local dependencies if they don't exist
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}
test_and_check:
<<: *defaults
steps:
- restore_cache:
keys:
- v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Testing
command: ./grailsw test-app
- run:
name: Executing stylecheck
command: ./gradlew check
- store_artifacts:
path: ./build/reports/codenarc
destination: codenarc-report
- store_test_results:
path: ./build/test-results/test
- store_artifacts:
path: ./build/reports/tests
destination: test-report
deploy_to_prod:
<<: *defaults
steps:
- restore_cache:
keys:
- v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- *assemble_prod
- *remote_docker
- *build_and_push_docker_image
- add_ssh_keys:
fingerprints:
- "9c:0c:ce:67:62:74:f1:d7:aa:b4:46:55:56:51:e5:f7"
- run:
name: Deploy
command: |
sudo apt-get update
sudo apt-get -y install gettext-base
sudo apt-get clean
envsubst < docker/deploy-prod.sh.template > docker/deploy-prod.sh
ssh -v -o StrictHostKeyChecking=no root#178.128.78.7 "bash -s" -- < ./docker/deploy-prod.sh
workflows:
version: 2
build-and-test:
jobs:
- checkout_code
- compile:
requires:
- checkout_code
- test_and_check:
requires:
- compile
- deploy_to_prod:
requires:
- test_and_check
filters:
branches:
only: master
If I log in with SSH, and trying to execute the same thing by hand, I am getting the same error. Also, checked if there is a network connection. All good...
What can be the reason for this error?
This is caused by a problem with the Artifactory instance. More information is available at github.com/grails/grails-wrapper/issues/7 and github.com/grails/grails-core/issues/11825.
The Grails Repository has been moved to an artifactory instance and the paths have changed.
You may have to update your maven repository url in build.gradle:
# Old repository url
maven { url "https://repo.grails.org/grails/core" }
# New url
maven { url "https://repo.grails.org/artifactory/core/" }
The only official information I found about this change was Important Information Regarding Grails and Bintray.
You can find all available repositories here. (In case you need the plugins repository or anything else.)
I hope that fixes your problem.
Regards

Bitbucket Pipeline, Artifacts between steps

I am trying to use the following pipeline in bitbucket to deploy to gcloud. The rest of the pipeline is missing but I know that works. The issue is when I get to step two the compiled CSS files are no longer existing. It appears to match what bitbucket suggest for using artifacts. I tried the following;
artifacts:
- **
-public/assets/css/generated/style.css
-public/assets/css/generated/*.css
-public/assets/css/generated/*
-public/*
-public/**
.
pipelines:
branches:
pipeline:
- step:
image: node:4.6.0
caches:
- node
script:
- cd web-application
- npm install
- npm install -g gulp
- gulp
- ls public/assets/css/generated
# - mv public/assets/css/generated/* ~/./
- cd ..
artifacts:
- public/assets/css/generated/style.css
- public/**
- step:
image: google/cloud-sdk:latest
script:
- cd web-application
- ls public/assets/css/generated
Artifacts showing in step 1

How to make TravisCI run flow/test/lint in parallel?

In my .travis.yml I have this.
script:
- yarn lint
- yarn flow
- yarn test --runInBand
I was wondering is there a way to get them to run in parallel?
There's few suggestions in Travis docs you could use, i.e. split your build into multiple jobs: https://docs.travis-ci.com/user/speeding-up-the-build/
Another thing you could do is to employ GNU parallel:
addons:
apt_packages:
- parallel
script:
- parallel --gnu --keep-order ::: 'yarn lint' 'yarn flow' 'yarn test --runInBand'
The GNU parallel command has lots of options you might want to tweak to your needs. Read more about the tool on their website https://www.gnu.org/software/parallel/
To split Travis into several jobs you can either use stages or add the option env
This would run each script sequentially:
script:
- yarn lint
- yarn flow
- yarn test --runInBand
- yarn build
- yarn cypress
To get them to run in parallel jobs. You can update it to the code below (Though keep in mind this is limited by the number of concurrent jobs available. https://travis-ci.com/plans)
Using Build Stages
language: node_js
node_js:
- '9'
install:
- travis_retry yarn install
jobs:
include:
- stage: test
name: "Flow/Lint/Test"
script:
- yarn lint
- yarn flow
- yarn test
-
name: "Cypress"
script:
- yarn cypress
Using env
env:
- TEST_SUITE="yarn lint"
- TEST_SUITE="yarn flow"
- TEST_SUITE="yarn test --runInBand"
- TEST_SUITE="yarn build"
- TEST_SUITE="yarn cypress"
script: $TEST_SUITE
Another option would be to just have two concurrent builds.
env:
- TEST_SUITE="yarn lint && yarn flow && yarn test --runInBand && yarn build"
- TEST_SUITE="yarn cypress"
script: $TEST_SUITE
This might or might not improve the overall build times. For me majority of my build time was in cypress while lint + flow + test took a few minutes. So by separating cypress to be in its own job, I sped up my overall build time by a few minutes.

How to exclude stage/job conditionally with travis build stages (beta feature)

Trying to get travis to skip release stage for PR/non master branch builds but I can't seem to get the recipe right.
The travis config is listed here:
language: node_js
cache:
directories:
- node_modules
node_js:
- '8'
- '6'
before_install:
- npm install -g npm#5
- npm install -g greenkeeper-lockfile#1
install:
- yarn install --ignore-engines
before_script: greenkeeper-lockfile-update
after_script: greenkeeper-lockfile-upload
script:
- yarn coveralls
branches:
except:
- /^v\d+\.\d+\.\d+$/
jobs:
include:
- if: branch = master
- stage: release
node_js: lts/*
script: echo "Deploying to npm ..."
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
I also tried
jobs:
include:
- stage: release
if: branch = master
node_js: lts/*
script: echo "Deploying to npm ..."
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
and
jobs:
include:
-
if: branch = master
- stage: release
node_js: lts/*
script: echo "Deploying to npm ..."
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
but travis always executes the release stage - it doesn't run npx semantic-release but it still goes through initializing, running tests etc.

Is it possible to set conditional environment variables in travis?

I am running on travis on 5 versions of nodeJS, .travis.yml is ....
language: node_js
node_js:
- 5.0
- 4.0
- 0.12.7
- 0.10.40
- 0.10.36
before_install:
- npm install -g grunt-cli
script:
- npm run travis
I want to set a travis environment variable for the run on nodeJS 5.0 only
something like this ...
language: node_js
node_js:
- 5.0
- env: POST_TO_COVERALLS=true
- 4.0
- 0.12.7
- 0.10.40
- 0.10.36
before_install:
- npm install -g grunt-cli
script:
- npm run travis
but this is invalid ... anyone know how to do this ...
1 - Preferably, via .travis.yml
2 - If not, through the travis web application
I KNOW HOW TO DO THIS VIA CODE - But can it be done through travis?
Thanks all
Newly introduced Travis build stages combined with some YML inheritance and and some hacking around assigning the Bash variable can be very handy for this:
jobs:
include:
- stage: Tests
script: # run tests
- script: # run more tests
- &deploy-stuff
stage: Deploy
if: branch != master
env:
- ENV=$(if [ "$SOMETHING" = "thing" ]; then echo ${TRAVIS_BRANCH//\//-}; else echo "staging"; fi)
script: # do some things before deploy
deploy:
- provider: script
skip_cleanup: true
script: echo $ENV
on:
all_branches: true
condition: $TRAVIS_BRANCH = "devel" || $SOMETHING = "thing"
- <<: *deploy-stuff
if: branch = master
env:
- ENV="production"
deploy:
- provider: script
skip_cleanup: true
script: echo $ENV
on:
branch: master
What about using the matrix to explicitly include the one "5.0" build where your environment variable is set to true (see documentation on explicitly including builds).
It would be something like the following
language: node_js
node_js:
- 4.0
- 0.12.7
- 0.10.40
- 0.10.36
env:
POST_TO_COVERALLS=false
matrix:
include:
- node_js: 5.0
env: POST_TO_COVERALLS=true
before_install:
- npm install -g grunt-cli
script:
- npm run travis

Resources