Skip to content

Commit

Permalink
ISD-1657 add declarative pipeline plugin integration test (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanhphan1147 authored Mar 13, 2024
1 parent 704ec4a commit fcc3cc9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ options:
Comma-separated list of allowed plugin short names. If empty, any plugin can be installed.
Plugins installed by the user and their dependencies will be removed automatically if not on
the list. Included plugins are not automatically installed.
default: "bazaar,blueocean,dependency-check-jenkins-plugin,docker-build-publish,git,kubernetes,ldap,matrix-combinations-parameter,oic-auth,openid,pipeline-groovy-lib,postbuildscript,rebuild,reverse-proxy-auth-plugin,ssh-agent,thinBackup"
default: "bazaar,blueocean,dependency-check-jenkins-plugin,docker-build-publish,git,kubernetes,ldap,matrix-combinations-parameter,oic-auth,openid,pipeline-groovy-lib,postbuildscript,rebuild,reverse-proxy-auth-plugin,ssh-agent,thinBackup,pipeline-model-definition"
24 changes: 24 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,30 @@ def kubernetes_test_pipeline_script() -> str:
)


def declarative_pipeline_script() -> str:
"""Generate a declarative pipeline script.
Return:
The pipeline script
"""
return textwrap.dedent(
"""
pipeline {
agent any
stages {
stage('Integration Test') {
steps {
sh'''#!/bin/bash
echo "$(hostname) $(date) : Running in $(pwd)"
'''
}
}
}
}"""
)


def create_secret_file_credentials(
unit_web_client: UnitWebClient, kube_config: str
) -> typing.Optional[str]:
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .helpers import (
create_kubernetes_cloud,
create_secret_file_credentials,
declarative_pipeline_script,
gen_git_test_job_xml,
gen_test_job_xml,
gen_test_pipeline_with_custom_script_xml,
Expand Down Expand Up @@ -578,3 +579,24 @@ async def test_kubernetes_plugin(unit_web_client: UnitWebClient, kube_config: st
logs = "".join(log_stream)
logger.debug("build logs: %s", logs)
assert build.get_status() == "SUCCESS"


@pytest.mark.usefixtures("k8s_agent_related_app")
async def test_pipeline_model_definition_plugin(unit_web_client: UnitWebClient):
"""
arrange: given a Jenkins charm with declarative pipeline plugin installed.
act: Run a job using a declarative pipeline script.
assert: Job succeeds.
"""
await install_plugins(unit_web_client, ("pipeline-model-definition",))

job = unit_web_client.client.create_job(
"pipeline_model_definition_plugin_test",
gen_test_pipeline_with_custom_script_xml(declarative_pipeline_script()),
)

queue_item = job.invoke()
queue_item.block_until_complete()

build: jenkinsapi.build.Build = queue_item.get_build()
assert build.get_status() == "SUCCESS"

0 comments on commit fcc3cc9

Please sign in to comment.