This is a shared library for Jenkins for running moodle-plugin-ci
It is currently a work in progress and contributions are very welcome!
- multiple PHP versions
- mysql and postgres
- behat
- additional PHP modules
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.
- php: a PHP version, e.g. 7.4
- db: mysql or postgres
- withBehatServers: chrome or firefox. This will start the relevant selenium container and the PHP built-in web server to allow the behat command to be run.
- ciVersion the version of moodle-plugin-ci to use
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.
- command line parameters for the moodle-plugin-ci install command. The following parameters are managed by the step and are not permitted: db-type, db-user, db-pass, db-host
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://[email protected]/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.
- command: the moodle-plugin-ci command to be run, along with any parameters
- stageResult (optional): the stage result if the command fails (default SUCCESS)
- buildResult (optional): the build result if the command fails (default FAILURE)
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 :)