Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert plugin testing to pipelines #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions theforeman.org/pipelines/test/foreman_plugin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
pipeline {
options {
timestamps()
timeout(time: 2, unit: 'HOURS')
ansiColor('xterm')
}

agent none

stages {
stage('Test') {
matrix {
agent { label 'fast' }
axes {
axis {
name 'ruby'
values '2.5', '2.6', '2.7'
}
}
stages {
stage('Configure Environment') {
steps {
configureRVM(ruby)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be nice as a stage.

deleteDir()
checkout scm: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git steps could be nice as a stage.

$class: 'GitSCM',
branches: [[name: params.plugin_branch]],
userRemoteConfigs: [[url: params.plugin_repo]],
extensions: [[$class: 'CloneOption', shallow: true, noTags: true]]
],
poll: false

dir('foreman') {
checkout scm: [
$class: 'GitSCM',
branches: [[name: params.foreman_branch]],
userRemoteConfigs: [[url: params.foreman_repo]],
extensions: [[$class: 'CloneOption', shallow: true, noTags: true]]
],
poll: false

addGem()
databaseFile(gemset())
configureDatabase(ruby)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be nice as a stage.

}
}
}
stage('Unit Tests') {
steps {
dir('foreman') {
withRVM(['bundle exec rake jenkins:unit TESTOPTS="-v" --trace'], ruby)
}
}
}
stage('Acceptance Tests') {
when {
allOf {
equals expected: '2.7', actual: ruby
expression { fileExists('test/integration') }
}
}
steps {
dir('foreman') {
withRVM(
[
'bundle exec npm install',
'bundle exec rake webpack:compile jenkins:integration TESTOPTS="-v" --trace'
],
ruby
)
}
}
}
stage('Javascript') {
when {
allOf {
equals expected: '2.7', actual: ruby
expression { fileExists('package.json') }
}
}
steps {
sh "npm install"
sh 'npm test'
}
}
stage('assets-precompile') {
steps {
dir('foreman') {
withRVM(["bundle exec rake plugin:assets:precompile[${params.plugin_name}] RAILS_ENV=production --trace"], ruby)
}
}
}
stage('Test db:seed') {
environment {
RAILS_ENV = 'test'
}
steps {
dir('foreman') {
withRVM(
[
'bundle exec rake db:drop || true',
'bundle exec rake db:create',
'bundle exec rake db:migrate',
'bundle exec rake db:seed'
],
ruby
)
}
}
}
}
post {
always {
dir('foreman') {
archiveArtifacts artifacts: "log/test.log"
junit keepLongStdio: true, testResults: 'jenkins/reports/unit/*.xml'
cleanup(ruby)
}
deleteDir()
// ircNotify TODO
}
}
}
}
}
}
8 changes: 0 additions & 8 deletions theforeman.org/yaml/jobs/plugins/foreman-tasks.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions theforeman.org/yaml/jobs/plugins/foreman_ansible.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions theforeman.org/yaml/jobs/plugins/foreman_bootdisk.yaml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions theforeman.org/yaml/jobs/plugins/foreman_digitalocean.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions theforeman.org/yaml/jobs/plugins/foreman_discovery.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions theforeman.org/yaml/jobs/plugins/foreman_hooks.yaml

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions theforeman.org/yaml/jobs/plugins/foreman_kubevirt.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions theforeman.org/yaml/jobs/plugins/foreman_openscap.yaml

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions theforeman.org/yaml/jobs/plugins/foreman_salt.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions theforeman.org/yaml/jobs/plugins/foreman_setup.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions theforeman.org/yaml/jobs/plugins/foreman_templates.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions theforeman.org/yaml/jobs/plugins/puppetdb_foreman.yaml

This file was deleted.

135 changes: 135 additions & 0 deletions theforeman.org/yaml/jobs/test_plugin_pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# parameters:
# name: plugin name, e.g. foreman_bootdisk
# repo: git repo name as it may differ, e.g. foreman_bootdisk
# branch: git repo branch to test, e.g. master
# foreman_branch: foreman git repo branch to run on, e.g. develop
- job-template:
name: 'test_foreman_plugin_{plugin}_{branch}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice here to update to newer naming conventions as part of the shift. I think it would translate to:

foreman-plugin-{plugin}-{branch}-test

foreman-plugin-discovery-develop-test
foreman-plugin-ansible-master-test
foreman-plugin-remote_execution-master-test

project-type: pipeline
sandbox: true
properties:
- github:
url: '{repo}'
- tfm-build-discarder
parameters:
- string:
name: plugin_repo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd to me to generate a dedicated job to a plugin and then be able to change the repo of the plugin as an input to the job.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a job template and this was the easiest way I knew to avoid creating a file to set a variable for every plugin.

default: '{repo}'
description: "Git URL containing the Foreman plugin, e.g. <pre>https://github.com/theforeman/foreman_example</pre>"
- string:
name: plugin_branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd to me to generate a dedicated branch job to a plugin and then be able to change the branch being tested of the plugin as an input to the job.

default: '{branch}'
description: "Git branch name of the Foreman plugin, e.g. <pre>master</pre>"
- string:
name: plugin_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd to me to generate a dedicated job to a plugin and then be able to change the name of the plugin as an input to the job.

default: '{plugin}'
description: "Name of the Foreman plugin/gem, in the format that should be in the Gemfile, e.g. <pre>foreman_test</pre>"
- string:
name: foreman_repo
default: https://github.com/theforeman/foreman
description: "Git URL containing Foreman itself, which the plugin will be added to,
e.g. <pre>https://github.com/theforeman/foreman</pre>"
- string:
name: foreman_branch
default: '{foreman_branch}'
description: "Git branch name of Foreman itself, e.g. <pre>develop</pre>"
quiet-period: 1200
triggers:
- github
- pollscm:
cron: 'H/15 * * * *'
- timed: 'H H * * 6'
dsl:
!include-raw:
- pipelines/lib/rvm.groovy{empty}
- pipelines/lib/foreman.groovy{empty}
- pipelines/test/foreman_plugin.groovy{empty}
publishers:
- ircbot_freenode

# Foreman plugins that follow the conventions
- project:
name: foreman-plugins-standard
plugin:
- ansible
- bootdisk
- default_hostgroup
- extra_hosts
- host_extra_validator
- kubevirt
- monitoring
- omaha
- openscap
- remote_execution
- salt
- setup
- templates
branch: master
foreman_branch: develop
repo: 'https://github.com/theforeman/foreman_{plugin}'
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'

# Git repo uses a dash instead of an underscore
- project:
name: foreman-plugin-digitalocean
plugin: digitalocean
repo: https://github.com/theforeman/foreman-digitalocean
branch: master
foreman_branch: develop
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'

# Project name doesn't start with foreman_
- project:
name: foreman-plugin-puppetdb
plugin: puppetdb
repo: https://github.com/theforeman/puppetdb_foreman
branch: master
foreman_branch: develop
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'

# Multiple branches
- project:
name: foreman-plugin-bootdisk
plugin: bootdisk
repo: https://github.com/theforeman/foreman_discovery
branch:
- master:
foreman_branch: develop
- 17.0-stable:
foreman_branch: 2.1-stable
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'
name: foreman-plugin-discovery
plugin: discovery
repo: https://github.com/theforeman/foreman_discovery
branch:
- develop:
foreman_branch: develop
- 16.1-stable:
foreman_branch: 2.1-stable
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'

# Multiple branches and git repo uses a dash
- project:
name: foreman-plugin-tasks
plugin: tasks
repo: https://github.com/theforeman/foreman-tasks
branch:
- master:
foreman_branch: develop
- 0.16.x:
foreman_branch: 1.23-stable
- 0.15.x:
foreman_branch: 1.22-stable
empty: ''
jobs:
- 'test_foreman_plugin_{plugin}_{branch}'