Files
gitlab-ci/lint/ansible.gitlab-ci.yaml
Jon 04e7e928e0 feat(ci_rules): add exists and changes for rules
now defined jobs check for existance of file and for changes
to launch a job

!41 #32
2023-06-02 15:26:35 +09:30

71 lines
2.7 KiB
YAML

.ansible_linter_defaults:
stage: validation
variables:
ANSIBLE_LINT_PATH: defaults/ handlers/ meta/ tasks/ templates/
before_script:
- if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi
- echo "[DEBUG] ROOT_DIR[$ROOT_DIR]"
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
- export PYTHON_VERSION=`python -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}.{2}".format(*version))'`
- apt update
- apt install --no-install-recommends -y git
- python3 -m venv env
- . env/bin/activate
- pip install --upgrade pip
- pip install -r $ROOT_DIR/lint/requirements.txt
- mkdir $PYTHON_VERSION
script:
- ansible-lint -q --nocolor --parseable $ANSIBLE_LINT_PATH > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-ansible-lint.log" 1>&1 || ANSIBLE_LINT=$?
- cat "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-ansible-lint.log" | ansible-lint-to-junit-xml > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$PYTHON_VERSION-ansible-lint.junit.xml" 1>&1 || ANSIBLE_LINT_JUNIT=$?
- ls -la $PYTHON_VERSION
- if [ $ANSIBLE_LINT_JUNIT > 0 ]; then echo "Error ANSIBLE_LINT_JUNIT failed with $ANSIBLE_LINT_JUNIT"; fi
- if [ $ANSIBLE_LINT -ge 3 ]; then echo "ansible lint failed with $ANSIBLE_LINT"; exit $ANSIBLE_LINT; fi # don't fail the job?? 1=failed test, 2=failed command i.e. switch/flag
after_script:
- echo deactivate
artifacts:
expire_in: 3 days
when: always
paths:
- "artifacts/*"
reports:
junit:
- "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
rules:
- if: '$JOB_STOP_ANSIBLE_LINT'
when: never
- if: # condition_master_branch_push
$CI_COMMIT_BRANCH == "master" &&
$CI_PIPELINE_SOURCE == "push"
exists:
- '{defaults/**,handlers/**,meta/**,tasks/**}/*.yaml'
when: always
- if: # condition_dev_branch_push
$CI_COMMIT_BRANCH == "development" &&
$CI_PIPELINE_SOURCE == "push"
exists:
- '{defaults/**,handlers/**,meta/**,tasks/**}/*.yaml'
changes:
paths:
- '{defaults/**,handlers/**,meta/**,tasks/**}/*.yaml'
compare_to: 'master'
when: always
- if: # condition_not_master_or_dev_push
$CI_COMMIT_BRANCH != "master" &&
$CI_COMMIT_BRANCH != "development" &&
$CI_PIPELINE_SOURCE == "push"
exists:
- '{defaults/**,handlers/**,meta/**,tasks/**}/*.yaml'
changes:
paths:
- '{defaults/**,handlers/**,meta/**,tasks/**}/*.yaml'
compare_to: 'development'
when: always
- when: never