diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .tox - +jenkins-token \ No newline at end of file diff --git a/jobs/swh-packages.yaml b/jobs/swh-packages.yaml --- a/jobs/swh-packages.yaml +++ b/jobs/swh-packages.yaml @@ -1,11 +1,15 @@ - job-group: name: "swh-jobs-{name}" + gitlab_url: https://gitlab-staging.swh.network + gitlab_connection_name: gitlab-staging + gitlab_project_name: "swh/devel/{repo_name}" jobs: - "{name}" - "{name}/incoming-tag" - "{name}/pypi-upload" - "{name}/tests" - "{name}/tests-on-diff" + - "{name}/gitlab-tests" - "debian/packages/{name}" - "debian/packages/{name}/update-for-release" - "debian/packages/{name}/automatic-backport" diff --git a/jobs/templates/swh-pipeline-diff.yaml b/jobs/templates/swh-pipeline-diff.yaml --- a/jobs/templates/swh-pipeline-diff.yaml +++ b/jobs/templates/swh-pipeline-diff.yaml @@ -10,6 +10,7 @@ sandbox: true auth-token: "ph4br1cat0r" phabricator_diff: true + gitlab_project: false do_cypress: false timeout: 10 max_concurrent: 0 diff --git a/jobs/templates/swh-pipeline.groovy.j2 b/jobs/templates/swh-pipeline.groovy.j2 --- a/jobs/templates/swh-pipeline.groovy.j2 +++ b/jobs/templates/swh-pipeline.groovy.j2 @@ -16,33 +16,60 @@ ) } + {%- if not gitlab_project %} environment { PHAB_CONDUIT_URL = 'https://forge.softwareheritage.org/api/' } + {%- endif %} stages { stage('Checkout') { steps { + {%- if not gitlab_project %} {% filter indent(width=8) %} {%- include 'includes/create-phabricator-artifacts.groovy.j2' -%} {% endfilter %} + {%- else %} + updateGitlabCommitStatus name: 'jenkins', state: 'running' + {%- endif %} checkout([ $class: 'GitSCM', - branches: [[name: "${params.REVISION}"]], + {%- if gitlab_project %} + userRemoteConfigs: [[ + url: '{{gitlab_url}}/{{gitlab_project_name}}.git', + refspec: '+refs/heads/*:refs/remotes/origin/* \ + +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/* \ + +refs/tags/*:refs/remotes/origin/tags*', + ]], + branches: [[ + name: params.REVISION ?: "${env.gitlabSourceBranch}" + ]], + browser: [ + $class: 'GitLab', + repoUrl: '{{gitlab_url}}/{{gitlab_project_name}}' + ], + {%- else %} + userRemoteConfigs: [[ + url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git', + refspec: '+refs/heads/master:refs/remotes/origin/master', + ]], + branches: [[ + name: "${params.REVISION}" + ]], + browser: [ + $class: 'Phabricator', + repoUrl: 'https://forge.softwareheritage.org', repo: '{{name}}' + ], + {%- endif %} doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', honorRefspec: true]], gitTool: 'Default', submoduleCfg: [], - userRemoteConfigs: [ - [url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git', - refspec: '+refs/heads/master:refs/remotes/origin/master'], - ], - browser: [$class: 'Phabricator', repoUrl: 'https://forge.softwareheritage.org', repo: '{{name}}'] ]) } } - {%- if phabricator_diff %} + {%- if not gitlab_project and phabricator_diff %} stage('Apply phabricator diff') { steps { {% filter indent(width=8) %} @@ -132,6 +159,17 @@ } // stages post { + {%- if gitlab_project %} + failure { + updateGitlabCommitStatus name: 'jenkins', state: 'failed' + } + success { + updateGitlabCommitStatus name: 'jenkins', state: 'success' + } + aborted { + updateGitlabCommitStatus name: 'jenkins', state: 'canceled' + } + {%- else %} always { step([$class: 'PhabricatorNotifier', commentOnSuccess: true, @@ -144,6 +182,7 @@ lintFileSize: '1000000', ]) } // always + {%- endif %} cleanup { cleanWs() diff --git a/jobs/templates/swh-pipeline.yaml b/jobs/templates/swh-pipeline.yaml --- a/jobs/templates/swh-pipeline.yaml +++ b/jobs/templates/swh-pipeline.yaml @@ -1,4 +1,4 @@ -- job-template: +- job-template: &master_tests name: "{name}/tests" display-name: "master branch" project-type: pipeline @@ -16,6 +16,7 @@ days-to-keep: 90 artifact-num-to-keep: 20 phabricator_diff: false + gitlab_project: false do_cypress: false timeout: 10 max_concurrent: 0 @@ -34,3 +35,29 @@ default: "{default-tox-environment}" dsl: !include-jinja2: swh-pipeline.groovy.j2 + +- job-template: + name: "{name}/gitlab-tests" + display-name: "GitLab builds" + auth-token: + properties: + - gitlab: + connection: "{gitlab_connection_name}" + triggers: + - gitlab: + trigger-push: true + trigger-merge-request: true + add-ci-message: true + cancel-pending-builds-on-update: true + # secret jenkins token is generated when executing tox + secret-token: !include-raw: jenkins-token + gitlab_project: true + parameters: + - string: + name: REVISION + description: Git revision to build. + - string: + name: TOX_ENVIRONMENT + description: tox environment to use for the main tox run + default: "{default-tox-environment}" + <<: *master_tests diff --git a/tox.ini b/tox.ini --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,10 @@ skip_install = true deps = jenkins-job-builder + [testenv:test] +allowlist_externals = bash commands = + # generate secret jenkins token to trigger builds from gitlab webhooks + bash -c "echo -n $(openssl rand -base64 32 | sha1sum | cut -c1-40) > jobs/templates/jenkins-token" jenkins-jobs {posargs:test} -r jobs