University-of-Strathclyde-LTE-Team / moodle-plugin-ci-jenkins

A Jenkins shared library for running moodle-plugin-ci
2 stars 1 forks source link

This is a shared library for Jenkins for running moodle-plugin-ci

It is currently a work in progress and contributions are very welcome!

Feature support

Supported

Not supported

Requirements

Docker must be available on the Jenkins server.

The following Jenkins plugins must also be installed:

Usage

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.

withMoodlePluginCiContainer

This starts up a docker container with a suitable environment for running moodle-plugin-ci.

Parameters

The step also expects a code block which will be run inside the container

Example

withMoodlePluginCiContainer(php: 7.4, db: postgres) {
    sh 'moodle-plugin-ci --help'
}

The other two steps are intended to be run inside the container step.

moodlePluginCiInstall

This runs the moodle-plugin-ci install command inside the container.

Parameters

Examples

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')
    }
}

moodlePluginCi

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.

Parameters

The result parameters are strings as supported by the Jenkins catchError step.

For example:

moodlePluginCi 'codechecker --max-warnings 0', 'SUCCESS', 'SUCCESS'

Full pipeline example

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'
                }
            }
        }
    }
}

Workspace

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.

Contributing

Any pull requests for improvements are very welcome. The project uses git flow so please raise any pull requests against the develop branch :)