Revisit plugin test target detection

The way it is currently implemented to detect test targets is error
prone. In case of find-owners plugin there are two test targets:

$ grep -2 junit_tests BUILD | grep -o 'name = "[^"]*"' | cut -d '"' -f 2
findowners_junit_tests
findowners_IT_tests

But the code assumes that there are only one single target:

if [ "$TEST_TARGET" != "" ]
then
  bazelisk test --test_env DOCKER_HOST=$DOCKER_HOST plugins/{name}:$TEST_TARGET
fi

And this is why the second target findowners_IT_tests gets orphaned and
is not prefixed with "plugins/{name}" prefix and thus not found.

Moreover, this approach to grep for targets can also lead to false
negative results, because the test rules might be located in nested
plugin packages but not in the root package, like it is the case for
checks plugin. For such plugins no test are executed at all.

To rectify, avoid grep and just use Bazel's native wildcard "/..."
target feature, that should work in all three possible cases:

1. no test rule exist
2. one single test rule exsits in plugin's root package
3. many test rules exist in root and/or nested packages

This approach has problem with exit code of bazel in case that there are
no tests even thoufg test run was requested.

As documented in the user guide: [1], it is expected that Bazel
unconditionally returns exit code 4 in this situation. Check for that
exit code explicitly and warn CI users to contact plugin maintainers if
there were no tests found. Let's face it: the code is inherently broken
if there are no tests at all. Still we would like to avoid the
boilerplate to be needed and wrote this feature request: [2].

[1] https://docs.bazel.build/versions/master/guide.html#what-exit-code-will-i-get
[2] https://github.com/bazelbuild/bazel/issues/11465

Bug: Issue 12512
Change-Id: Id641cfd2300939d3eac5adb4cdc4a14b12d5f7c2
5 files changed
tree: ac5cc82f2c0fdb5bd67a837ed3010e6b62fc9986
  1. jenkins/
  2. jenkins-docker/
  3. vars/
  4. worker/
  5. .gitignore
  6. Jenkinsfile
  7. README.md
  8. yamllint-config.yaml
README.md

Gerrit CI scripts

Providing jobs

This project uses Jenkins Jobs Builder [1] to generate jobs from yaml descriptor files.

To add new jobs reuse existing templates, defaults etc. as much as possible. E.g. adding a job to build an additional branch of a project may be as easy as adding the name of the branch to an existing project.

To ensure well readable yaml-files, use yamllint [2] to lint the yaml-files. Yamllint can be downloaded using Python Pip:

pip3 install yamllint

To run the linter, execute this command from the project's root directory:

yamllint -c yamllint-config.yaml jenkins/**/*.yaml

Yamllint will not fix detected issues itself.

[1] https://docs.openstack.org/infra/jenkins-job-builder/index.html [2] https://pypi.org/project/yamllint/