This is a shared library for Jenkins for running moodle-plugin-ci
It is currently a work in progress and contributions are very welcome!
Docker must be available on the Jenkins server.
The following Jenkins plugins must also be installed:
The library is intended for use in Jenkins declarative pipelines (although may work in other scenarios).
It should be set up as normal for a shared library in the Jenkins global settings.
It provides some custom steps.
This starts up a docker container with a suitable environment for running moodle-plugin-ci.
The step also expects a code block which will be run inside the container
withMoodlePluginCiContainer(php: 7.4, db: postgres) {
sh 'moodle-plugin-ci --help'
}
The other two steps are intended to be run inside the container step.
This runs the moodle-plugin-ci install command inside the container.
withMoodlePluginCiContainer(php: 7.4, db: postgres) {
moodlePluginCiInstall('--branch MOODLE_310_STABLE --plugin plugin')
}
Using a custom Moodle repo
withMoodlePluginCiContainer(php: 7.4, db: postgres) {
ssh-agent(['bitbucket-credentials']) {
moodlePluginCiInstall('--branch MOODLE_310_STABLE --plugin plugin --repo ssh://git@bitbucket.example.com/moodle.git')
}
}
This is a wrapper step for moodle-plugin-ci which simplifies setting the stage and build status when the call fails. For example, you may wish to run codechecker without failing your build if issues are found, but to mark the build as unstable.
The result parameters are strings as supported by the Jenkins catchError step.
For example:
moodlePluginCi 'codechecker --max-warnings 0', 'SUCCESS', 'SUCCESS'
pipeline {
agent any
options {
checkoutToSubdirectory('plugin')
disableConcurrentBuilds()
}
stages {
stage("Plugin CI") {
agent any
steps {
withMoodlePluginCiContainer(php: '7.4', ciVersion: '4') {
moodlePluginCiInstall("--branch MOODLE_310_STABLE --plugin plugin")
moodlePluginCi 'phplint'
moodlePluginCi 'phpcpd', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'phpmd', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'codechecker --max-warnings 0', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'phpdoc', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'validate', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'savepoints', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'mustache', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'grunt --max-lint-warnings 0', 'SUCCESS', 'SUCCESS'
moodlePluginCi 'phpunit'
}
}
}
}
}
Please note that withMoodlePluginCiContainer runs in the root of the workspace and cleans it up after running. If this is not acceptable please consider running it in a custom workspace for the job. However, npm and composer packages are cached at the workspace level (and are not cleaned up) in order to prevent re-downloading all dependencies for each run.
Any pull requests for improvements are very welcome. The project uses git flow so please raise any pull requests against the develop branch :)