iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐈

Running Ansible-lint and yamllint on Jenkins with reviewdog Notifications

に公開

It's very convenient to integrate with reviewdog and see lint results on a PR to speed up the code review process.

About this article

This article describes how to integrate Ansible Lint and reviewdog in an environment using Jenkins as CI.

Pitfalls

Ansible Lint has an option called -p to output in pep8 format.
Also, reviewdog has a pre-defined format -f pep8, so it looks like it should work without any issues.
However, it seems the output from the Ansible Lint side is not strictly pep8, so it was necessary to set up a custom format as -efm="%f:%l: %m".

Shellscript on jenkins

A Jenkins shell script for integrating with the GitHub Pull Request Builder plugin.

#!/bin/sh

# Download reviewdog
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s

# Run Ansible-lint
ansible-lint -p site.yml > ansible-lint_result.txt
# Run yamllint
yamllint -f parsable site.yml > yamllint_result.txt

# Run reviewdog
export CI_PULL_REQUEST=${ghprbPullId}
export CI_REPO_OWNER=YOUR_ORG_NAME # Please change appropriately
export CI_REPO_NAME=YOUR_REPOSITORY_NAME # Please change appropriately
export CI_COMMIT=${ghprbActualCommit}
export REVIEWDOG_GITHUB_API_TOKEN=${NHN_NAVER_DEV_ADMIN_GITHUB_TOKEN}
export GITHUB_API=YOUR_GITHUB_API_URL # Please change appropriately

cat ansible-lint_result.txt |  ./bin/reviewdog -name=ansible-lint -efm="%f:%l: %m" -reporter=github-pr-review
cat yamllint_result.txt | ./bin/reviewdog -name=yamllint -f=pep8 -reporter=github-pr-review

Discussion