From b7ee539bc53f7519bb310981c19b2a6a291fcf36 Mon Sep 17 00:00:00 2001 From: tanhengyeow Date: Mon, 17 Sep 2018 01:18:03 +0800 Subject: [PATCH] docker-pull-image: Pull Docker image from Docker Hub/Registry Change-Id: I66e638564605fd25504b6e06524a26f778880f06 Co-Authored-By: Anil Belur Signed-off-by: Tan Heng Yeow Signed-off-by: Anil Belur --- jenkins_jobs/modules/builders.py | 41 +++++++++++++++++++ .../fixtures/docker-pull-image-full.xml | 12 ++++++ .../fixtures/docker-pull-image-full.yaml | 5 +++ .../fixtures/docker-pull-image-minimal.xml | 12 ++++++ .../fixtures/docker-pull-image-minimal.yaml | 2 + 5 files changed, 72 insertions(+) create mode 100644 tests/builders/fixtures/docker-pull-image-full.xml create mode 100644 tests/builders/fixtures/docker-pull-image-full.yaml create mode 100644 tests/builders/fixtures/docker-pull-image-minimal.xml create mode 100644 tests/builders/fixtures/docker-pull-image-minimal.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 9a4e18389..302c2914d 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -4019,6 +4019,47 @@ def docker_build_publish(parse, xml_parent, data): registry, registry_data, mappings, fail_required=True) +def docker_pull_image(registry, xml_parent, data): + """yaml: docker-pull-image + Provides integration between Jenkins and Docker Hub, utilizing a + Docker Hub hook to trigger one (or more) Jenkins job(s). + Requires the Jenkins :jenkins-wiki:`CloudBees Docker Hub Notification + `. + + :arg str image: Image ID on DockerHub (default '') + :arg str docker-registry-url: URL to the Docker registry + you are using (default '') + :arg str credentials-id: Registry credentials (default '') + + Minimal example: + + .. literalinclude:: + /../../tests/builders/fixtures/docker-pull-image-minimal.yaml + + Full example: + + .. literalinclude:: + /../../tests/builders/fixtures/docker-pull-image-full.yaml + """ + docker_pull_image = XML.SubElement( + xml_parent, 'org.jenkinsci.plugins.registry.' + 'notification.DockerPullImageBuilder') + docker_pull_image.set('plugin', 'dockerhub-notification') + registry = XML.SubElement(docker_pull_image, 'registry') + registry.set('plugin', 'docker-commons') + mapping = [ + ('image', 'image', ''), + ] + helpers.convert_mapping_to_xml( + docker_pull_image, data, mapping, fail_required=False) + registry_mapping = [ + ('docker-registry-url', 'url', ''), + ('credentials-id', 'credentialsId', ''), + ] + helpers.convert_mapping_to_xml( + registry, data, registry_mapping, fail_required=False) + + def build_name_setter(registry, xml_parent, data): """yaml: build-name-setter Define Build Name Setter options which allows your build name to be diff --git a/tests/builders/fixtures/docker-pull-image-full.xml b/tests/builders/fixtures/docker-pull-image-full.xml new file mode 100644 index 000000000..81f5d4152 --- /dev/null +++ b/tests/builders/fixtures/docker-pull-image-full.xml @@ -0,0 +1,12 @@ + + + + + + https://index.docker.io/v1/ + 71e4f29c-162b-40d0-85d9-3ddfba2911a0 + + test-image-id + + + diff --git a/tests/builders/fixtures/docker-pull-image-full.yaml b/tests/builders/fixtures/docker-pull-image-full.yaml new file mode 100644 index 000000000..653be3839 --- /dev/null +++ b/tests/builders/fixtures/docker-pull-image-full.yaml @@ -0,0 +1,5 @@ +builders: + - docker-pull-image: + image: test-image-id + docker-registry-url: https://index.docker.io/v1/ + credentials-id: 71e4f29c-162b-40d0-85d9-3ddfba2911a0 diff --git a/tests/builders/fixtures/docker-pull-image-minimal.xml b/tests/builders/fixtures/docker-pull-image-minimal.xml new file mode 100644 index 000000000..0c379258c --- /dev/null +++ b/tests/builders/fixtures/docker-pull-image-minimal.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tests/builders/fixtures/docker-pull-image-minimal.yaml b/tests/builders/fixtures/docker-pull-image-minimal.yaml new file mode 100644 index 000000000..c0db1d247 --- /dev/null +++ b/tests/builders/fixtures/docker-pull-image-minimal.yaml @@ -0,0 +1,2 @@ +builders: + - docker-pull-image