diff --git a/jobs/templates/swh-cypress.groovy b/jobs/templates/swh-cypress.groovy index ee8c007..c4993fc 100644 --- a/jobs/templates/swh-cypress.groovy +++ b/jobs/templates/swh-cypress.groovy @@ -1,111 +1,111 @@ pipeline {{ agent {{ label '{docker-image}' }} environment {{ PHAB_CONDUIT_URL = 'https://forge.softwareheritage.org/api/' }} stages {{ stage('Checkout') {{ steps {{ withCredentials([ string(credentialsId: 'swh-public-ci', variable: 'PHAB_CONDUIT_TOKEN')]) {{ sh ''' if [ -n "$PHID" ]; then - echo "{ + echo "{{ \\\"buildTargetPHID\\\": \\\"$PHID\\\", \\\"artifactKey\\\": \\\"link.jenkins\\\", \\\"artifactType\\\": \\\"uri\\\", - \\\"artifactData\\\": { + \\\"artifactData\\\": {{ \\\"uri\\\": \\\"$BUILD_URL\\\", \\\"name\\\": \\\"Jenkins\\\", \\\"ui.external\\\": true - } - }" | arc call-conduit --conduit-uri $PHAB_CONDUIT_URL --conduit-token $PHAB_CONDUIT_TOKEN harbormaster.createartifact + }} + }}" | arc call-conduit --conduit-uri $PHAB_CONDUIT_URL --conduit-token $PHAB_CONDUIT_TOKEN harbormaster.createartifact python3 -m pyarcanist send-message work $PHID fi ''' }} checkout([$class: 'GitSCM', branches: [[name: "${{params.REVISION}}"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[url: 'https://forge.softwareheritage.org/source/{display-name}.git']] ]) }} }} stage('Setup environment') {{ steps {{ sh '''#!/bin/bash python3 -m venv ~/swh-web-env source ~/swh-web-env/bin/activate pip3 install wheel pip3 install -e .[testing] yarn install && yarn build-test && yarn run cypress install ''' }} }} stage('Run cypress tests') {{ steps {{ sh '''#!/bin/bash source ~/swh-web-env/bin/activate export PYTHONPATH=$PWD python3 swh/web/manage.py migrate --settings=swh.web.settings.tests python3 swh/web/manage.py createcachetable --settings=swh.web.settings.tests cat swh/web/tests/create_test_admin.py | python3 swh/web/manage.py shell --settings=swh.web.settings.tests python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & wait-for-it localhost:5004 yarn run cypress run yarn run mochawesome ''' }} }} }} post {{ always {{ withCredentials([ string(credentialsId: 'swh-public-ci', variable: 'PHAB_CONDUIT_TOKEN')]) {{ withEnv(["JOBSTATUS=${{currentBuild.currentResult}}"]) {{ sh ''' if [ "$JOBSTATUS" = "SUCCESS" ]; then MSGTYPE=pass else MSGTYPE=fail fi echo "Current job status is $JOBSTATUS -> $MGSTYPE" if [ -n "$PHID" ]; then python3 -m pyarcanist send-message $MSGTYPE $PHID fi ''' }} }} publishHTML (target: [ allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'cypress/mochawesome/report', reportFiles: 'mochawesome.html', reportName: "Mochawesome Tests Report" ]) publishHTML (target: [ allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'cypress/coverage/lcov-report', reportFiles: 'index.html', reportName: "Istanbul Code Coverage" ]) }} }} }} \ No newline at end of file diff --git a/jobs/templates/swh-pipeline.groovy b/jobs/templates/swh-pipeline.groovy index a8dff96..301e6cc 100644 --- a/jobs/templates/swh-pipeline.groovy +++ b/jobs/templates/swh-pipeline.groovy @@ -1,120 +1,120 @@ pipeline {{ agent {{ label '{docker-image}' }} environment {{ PHAB_CONDUIT_URL = 'https://forge.softwareheritage.org/api/' }} stages {{ stage('Checkout') {{ steps {{ withCredentials([ string(credentialsId: 'swh-public-ci', variable: 'PHAB_CONDUIT_TOKEN')]) {{ sh ''' if [ -n "$PHID" ]; then - echo "{ + echo "{{ \\\"buildTargetPHID\\\": \\\"$PHID\\\", \\\"artifactKey\\\": \\\"link.jenkins\\\", \\\"artifactType\\\": \\\"uri\\\", - \\\"artifactData\\\": { + \\\"artifactData\\\": {{ \\\"uri\\\": \\\"$BUILD_URL\\\", \\\"name\\\": \\\"Jenkins\\\", \\\"ui.external\\\": true - } - }" | arc call-conduit --conduit-uri $PHAB_CONDUIT_URL --conduit-token $PHAB_CONDUIT_TOKEN harbormaster.createartifact + }} + }}" | arc call-conduit --conduit-uri $PHAB_CONDUIT_URL --conduit-token $PHAB_CONDUIT_TOKEN harbormaster.createartifact python3 -m pyarcanist send-message work $PHID fi ''' }} checkout([$class: 'GitSCM', branches: [[name: "${{params.REVISION}}"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[url: 'https://forge.softwareheritage.org/source/{display-name}.git']] ]) }} }} stage('Static analysis') {{ steps {{ echo 'flake8' sh '''python3 -m detox -e flake8''' echo 'radon'; sh ''' mkdir -p reports python3 -m radon raw --json swh/ > reports/raw_report.json python3 -m radon cc --json swh/ > reports/cc_report.json python3 -m radon mi --json swh/ > reports/mi_report.json python3 -m radon hal --json swh/ > reports/hal_report.json python3 -m radon cc --xml swh/ > reports/cc_report.xml ''' }} }} // static analysis stage('Unit tests') {{ options {{ timeout(time: 20, unit: 'MINUTES') }} steps {{ sh ''' python3 -m tox -e py3 -- \ --cov-report=xml \ --junit-xml=test-results.xml ''' }} post {{ always {{ step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', failNoReports: false, failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 10, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false]) // JUnit report junit allowEmptyResults: true, testResults: 'test-results.xml' // disabled for now, requires the plugin Warning v5 (still in RC) //recordIssues enabledForFailure: true, // tools: [[pattern: '**/reports/cc_report.xml', tool: [$class: 'Ccm']]] }} }} // post }} // unit tests }} // stages post {{ always {{ // Archive a few report files archiveArtifacts allowEmptyArchive: true, artifacts: 'reports/*,*.xml,tox*.ini', fingerprint: true withCredentials([ string(credentialsId: 'swh-public-ci', variable: 'PHAB_CONDUIT_TOKEN')]) {{ withEnv(["JOBSTATUS=${{currentBuild.currentResult}}"]) {{ sh ''' if [ "$JOBSTATUS" = "SUCCESS" ]; then MSGTYPE=pass else MSGTYPE=fail fi echo "Current job status is $JOBSTATUS -> $MGSTYPE" if [ -n "$PHID" ]; then python3 -m pyarcanist send-message $MSGTYPE $PHID fi ''' }} // withEnv }} // withCredentials }} // always }} // post }} // pipeline \ No newline at end of file