1+ #! /usr/bin/env bash
2+
3+ set -e
4+
5+ PROJECT_ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && cd ../.. && pwd) "
6+ pushd " ${PROJECT_ROOT_DIR} "
7+
8+ # Use the jfdev-ci-commons as a library in the services.
9+ # This script downloads the jfdev-ci-commons npm package and extract the files inside it to the destination folder: build/ci/scripts/
10+ # The service will use the ci code locally.
11+ # In the service add in every step:
12+ # onStart:
13+ # - source "${res_<service>_bitbucket_resourcePath}/build/ci/pipelines_step_setup.sh"
14+ #
15+
16+
17+ JFDEV_CI_COMMONS_DEFAULT_VERSION=" 1.*"
18+
19+ if [[ -z " ${JFDEV_CI_COMMONS_VERSION} " ]]; then
20+ # Download latest release version (without milestone + dev versions) based on regex in 'JFDEV_CI_COMMONS_DEFAULT_VERSION'
21+ # Command breakdown:
22+ # jq -c '.[].props["npm.version"]' -> Return the value under [props][npm.version]
23+ # egrep -v -e "-m" -e "-dev" -> Remove the result with -m and -dev so in this case "1.2.0-dev" and "1.8.0-m016" will be removed
24+ # sort --version-sort -> Return asc sorted data for all version numeric-wise
25+ # tail -1 -> Return the last output print line since its already sorted
26+
27+ JFDEV_CI_COMMONS_VERSION=$( jfrog rt search " npm-releases-local/jfdev-ci-commons/-/jfdev-ci-commons-${JFDEV_CI_COMMONS_DEFAULT_VERSION} .tgz" | jq -cr ' .[].props["npm.version"][]' | egrep -v -e " -m" -e " -dev" | sort --version-sort | tail -1)
28+ echo " Found JFdev ci commons latest: ${JFDEV_CI_COMMONS_VERSION} "
29+ jfrog rt dl --explode " npm-releases-local/jfdev-ci-commons/-/jfdev-ci-commons-${JFDEV_CI_COMMONS_VERSION} .tgz"
30+ else
31+ # Download specific version user asked for in env var 'JFDEV_CI_COMMONS_VERSION' - could be release/milestone/dev
32+ jfrog rt dl --explode " */jfdev-ci-commons/-/jfdev-ci-commons-${JFDEV_CI_COMMONS_VERSION} .tgz"
33+ fi
34+
35+ CI_SCRIPTS_FOLDER=" ${PROJECT_ROOT_DIR} /.jfrog-pipelines/build/ci/scripts"
36+ echo " ${CI_SCRIPTS_FOLDER} "
37+ if [ -d " ${CI_SCRIPTS_FOLDER} " ]; then
38+ echo " ${CI_SCRIPTS_FOLDER} exists"
39+ # Directory ${CI_SCRIPTS_FOLDER} exists
40+ if [ " $( ls -A ${CI_SCRIPTS_FOLDER} ) " ]; then
41+ # Soon this folder will be removed from artifactory to jfdev-ci-commons repository.
42+ # After the remove this warning will become an error
43+ echo " [WARN] ${CI_SCRIPTS_FOLDER} is not empty"
44+ rm -rf " ${CI_SCRIPTS_FOLDER} /*"
45+ fi
46+ fi
47+
48+ mkdir -p " ${CI_SCRIPTS_FOLDER} " ; cp -Rf jfdev-ci-commons/-/package/* " ${CI_SCRIPTS_FOLDER} /"
49+
50+ source " ${CI_SCRIPTS_FOLDER} /lib/pipelineStepCommons.sh"
0 commit comments