← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~maas-committers/maas-ci/+git/maas-ci-config:jenkins-commit-status into ~maas-committers/maas-ci/+git/maas-ci-config:master

 

Review: Needs Fixing



Diff comments:

> diff --git a/jenkins/jobs/ansible_playbook.groovy b/jenkins/jobs/ansible_playbook.groovy
> new file mode 100644
> index 0000000..3c7ec88
> --- /dev/null
> +++ b/jenkins/jobs/ansible_playbook.groovy
> @@ -0,0 +1,88 @@
> +def updateCommitStatus(commit_sha, message, state) {
> +    step([
> +        $class: 'GitHubCommitStatusSetter',
> +        reposSource: [$class: "ManuallyEnteredRepositorySource", url: ${params.ANSIBLE_REPO}],
> +        commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commit_sha],
> +        statusResultSource: [
> +        $class: 'ConditionalStatusResultSource',
> +        results: [$class: "AnyBuildResult", message: message, state: state]
> +        ]
> +    ])
> +}
> +pipeline {
> +    agent {
> +        label 'ci-lab'
> +    }
> +    parameters {
> +        string(name: 'GIT_REPO', defaultValue: 'https://git.launchpad.net/~maas-committers/maas-ci/+git/system-tests', description: 'Git repo to pull system tests from')
> +        string(name: 'GIT_BRANCH', defaultValue: 'master', description: 'Branch in the repo to use')
> +        string(name: 'ANSIBLE_REPO', defaultValue: 'https://github.com/maas/maas-ansible-playbook.git', description: 'Git repo to pull Ansible playbook from')
> +        string(name: 'ANSIBLE_BRANCH', defaultValue: 'main', description: 'Branch in the Ansible playbook repo to use')
> +        string(name: 'PYTEST_ARGS', defaultValue: '--log-cli-level info', description: 'Additional args to pytest')
> +        string(name: 'CONTAINERS_IMAGE', defaultValue: 'ubuntu:22.04', description: 'LXD image for containers used in tests')
> +    }
> +    stages {
> +        stage('Checkout') {
> +            steps {
> +                sh """
> +                rm -rf system-tests
> +                git clone ${params.GIT_REPO} --branch ${params.GIT_BRANCH} --depth 1 system-tests
> +                env -C system-tests git show --no-patch
> +                """
> +            }
> +        }
> +        stage('Setup') {
> +            steps {
> +                sh """
> +                sudo apt-get install -y tox
> +                """
> +            }
> +        }
> +        stage('System Tests') {
> +            steps {
> +                writeFile file: 'system-tests/config.yaml', text: """
> +        proxy:
> +        http: http://squid.internal:3128

indentation here looks off

> +        containers-image: ${params.CONTAINERS_IMAGE}
> +        ansible-playbooks:
> +        git-repo: ${params.ANSIBLE_REPO}
> +        git-branch: ${params.ANSIBLE_BRANCH}
> +        """
> +                sh """
> +                cd system-tests

use dir("system-tests") to wrap the sh

> +                cat config.yaml
> +                export http_proxy=http://squid.internal:3128/
> +                export https_proxy=http://squid.internal:3128/
> +                tox r -e cog
> +                tox r -e ansible_tests -- ${params.PYTEST_ARGS}
> +                """
> +            }
> +        }
> +    }
> +    post {
> +        always {
> +            archiveArtifacts artifacts:'system-tests/*.log,system-tests/config.yaml,system-tests/junit*.xml', fingerprint: true
> +            junit allowEmptyResults: true, testResults: 'system-tests/junit*.xml'
> +            sh """
> +                lxc delete ansible-main --force || true
> +                lxc delete ansible-host-1 --force || true
> +                lxc delete ansible-host-2 --force || true
> +            """
> +            withCredentials([string(credentialsId: 'jenkins-maas-token', variable: 'API_TOKEN')]) {
> +                def logUrl = env.BUILD_URL + "artifact/system-tests/systemtests.ansible_tests.log"
> +                env.COMMIT_SHA = sh(
> +                    script: "curl -u ${API_TOKEN} -k " + logUrl + " | grep -oP '(?<=commit )[0-9a-f]{6,}'"
> +                    returnStdout: true
> +                ).trim()

just operate off of the local file instead of going back to Jenkins API?

> +              }
> +        }
> +        success {
> +            mattermostSend (color: 'green', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}](${env.BUILD_URL}) :success: was successful")
> +            updateCommitStatus("${env.COMMIT_SHA}", "${env.BUILD_URL}", "SUCCESS");
> +        }
> +        failure {
> +            mattermostSend (color: 'red', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}](${env.BUILD_URL}) :fire: failed")
> +            updateCommitStatus("${env.COMMIT_SHA}", "${env.BUILD_URL}", "FAILURE");
> +        }
> +    }
> +}


-- 
https://code.launchpad.net/~maas-committers/maas-ci/+git/maas-ci-config/+merge/437623
Your team MAAS Committers is subscribed to branch ~maas-committers/maas-ci/+git/maas-ci-config:master.



References