summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-02 13:31:54 +0000
committerGerrit Code Review <review@openstack.org>2019-01-02 13:31:54 +0000
commitb1499530dbb5ad66f52fbfc4ffa1343da79df441 (patch)
tree6e3855354347e625d0d9a0ad53b92589cdad6fbc
parent4e55ab1136d2b3d6f281c53d7c4e07a03ebf1d0b (diff)
parent039c860dc226a9ee64451f530e98791d3a9e810e (diff)
Merge "Add support for "Build / Publish Docker Image""
-rw-r--r--jenkins_jobs/modules/builders.py60
-rw-r--r--tests/builders/fixtures/build-publish-docker-image-full.xml19
-rw-r--r--tests/builders/fixtures/build-publish-docker-image-full.yaml10
-rw-r--r--tests/builders/fixtures/build-publish-docker-image-minimal.xml19
-rw-r--r--tests/builders/fixtures/build-publish-docker-image-minimal.yaml2
5 files changed, 110 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py
index 01cdd43..57199cd 100644
--- a/jenkins_jobs/modules/builders.py
+++ b/jenkins_jobs/modules/builders.py
@@ -3958,6 +3958,66 @@ def description_setter(registry, xml_parent, data):
3958 descriptionsetter, data, mapping, fail_required=True) 3958 descriptionsetter, data, mapping, fail_required=True)
3959 3959
3960 3960
3961def build_publish_docker_image(registry, xml_parent, data):
3962 """yaml: build-publish-docker-image
3963 Requires the Jenkins :jenkins-wiki:`CloudBees Docker Build and
3964 Publish plugin <CloudBees+Docker+Build+and+Publish+plugin>`.
3965
3966 :arg str docker-registry-url: URL to the Docker registry you are
3967 using (default '')
3968 :arg str image: Repository name to be applied to the resulting image
3969 in case of success (default '')
3970 :arg str docker-file-directory: Build step that sends a Dockerfile for
3971 building to docker host that used for this build run (default '')
3972 :arg bool push-on-success: Resulting docker image will be pushed to
3973 the registry (or registries) specified within the
3974 "Image" field (default false)
3975 :arg str push-credentials-id: Credentials to push to a private
3976 registry (default '')
3977 :arg bool clean-images: Option to clean local images (default false)
3978 :arg bool jenkins-job-delete: Attempt to remove images when jenkins
3979 deletes the run (default false)
3980 :arg str cloud: Cloud to use to build image (default '')
3981
3982 Minimal example:
3983
3984 .. literalinclude::
3985 /../../tests/builders/fixtures/build-publish-docker-image-minimal.yaml
3986
3987 Full example:
3988
3989 .. literalinclude::
3990 /../../tests/builders/fixtures/build-publish-docker-image-full.yaml
3991 """
3992 dbp = XML.SubElement(xml_parent,
3993 'com.nirima.jenkins.plugins.docker.builder'
3994 '.DockerBuilderPublisher')
3995 dbp.set('plugin', 'docker-plugin')
3996
3997 from_registry = XML.SubElement(dbp, 'fromRegistry')
3998 from_registry.set('plugin', 'docker-commons')
3999 from_registry_mapping = [
4000 ('docker-registry-url', 'url', ''),
4001 ]
4002 helpers.convert_mapping_to_xml(
4003 from_registry, data, from_registry_mapping,
4004 fail_required=False)
4005
4006 tags = XML.SubElement(dbp, 'tags')
4007 XML.SubElement(tags, 'string').text = data.get('image', '')
4008
4009 mapping = [
4010 ('docker-file-directory', 'dockerFileDirectory', ''),
4011 ('push-on-success', 'pushOnSuccess', False),
4012 ('push-credentials-id', 'pushCredentialsId', ''),
4013 ('clean-images', 'cleanImages', False),
4014 ('jenkins-job-delete', 'cleanupWithJenkinsJobDelete', False),
4015 ('cloud', 'cloud', ''),
4016 ]
4017 helpers.convert_mapping_to_xml(
4018 dbp, data, mapping, fail_required=False)
4019
4020
3961def docker_build_publish(parse, xml_parent, data): 4021def docker_build_publish(parse, xml_parent, data):
3962 """yaml: docker-build-publish 4022 """yaml: docker-build-publish
3963 Requires the Jenkins :jenkins-wiki:`Docker build publish Plugin 4023 Requires the Jenkins :jenkins-wiki:`Docker build publish Plugin
diff --git a/tests/builders/fixtures/build-publish-docker-image-full.xml b/tests/builders/fixtures/build-publish-docker-image-full.xml
new file mode 100644
index 0000000..d0e99bd
--- /dev/null
+++ b/tests/builders/fixtures/build-publish-docker-image-full.xml
@@ -0,0 +1,19 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <builders>
4 <com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher plugin="docker-plugin">
5 <fromRegistry plugin="docker-commons">
6 <url>Docker registry URL</url>
7 </fromRegistry>
8 <tags>
9 <string>Image string</string>
10 </tags>
11 <dockerFileDirectory>Directory for Dockerfile</dockerFileDirectory>
12 <pushOnSuccess>true</pushOnSuccess>
13 <pushCredentialsId>71e4f29c-162b-40d0-85d9-3ddfba2911a0</pushCredentialsId>
14 <cleanImages>true</cleanImages>
15 <cleanupWithJenkinsJobDelete>true</cleanupWithJenkinsJobDelete>
16 <cloud>cloud</cloud>
17 </com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher>
18 </builders>
19</project>
diff --git a/tests/builders/fixtures/build-publish-docker-image-full.yaml b/tests/builders/fixtures/build-publish-docker-image-full.yaml
new file mode 100644
index 0000000..2469d11
--- /dev/null
+++ b/tests/builders/fixtures/build-publish-docker-image-full.yaml
@@ -0,0 +1,10 @@
1builders:
2 - build-publish-docker-image:
3 docker-registry-url: Docker registry URL
4 image: Image string
5 docker-file-directory: Directory for Dockerfile
6 push-on-success: true
7 push-credentials-id: 71e4f29c-162b-40d0-85d9-3ddfba2911a0
8 clean-images: true
9 jenkins-job-delete: true
10 cloud: cloud
diff --git a/tests/builders/fixtures/build-publish-docker-image-minimal.xml b/tests/builders/fixtures/build-publish-docker-image-minimal.xml
new file mode 100644
index 0000000..3e61611
--- /dev/null
+++ b/tests/builders/fixtures/build-publish-docker-image-minimal.xml
@@ -0,0 +1,19 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <builders>
4 <com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher plugin="docker-plugin">
5 <fromRegistry plugin="docker-commons">
6 <url/>
7 </fromRegistry>
8 <tags>
9 <string/>
10 </tags>
11 <dockerFileDirectory/>
12 <pushOnSuccess>false</pushOnSuccess>
13 <pushCredentialsId/>
14 <cleanImages>false</cleanImages>
15 <cleanupWithJenkinsJobDelete>false</cleanupWithJenkinsJobDelete>
16 <cloud/>
17 </com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher>
18 </builders>
19</project>
diff --git a/tests/builders/fixtures/build-publish-docker-image-minimal.yaml b/tests/builders/fixtures/build-publish-docker-image-minimal.yaml
new file mode 100644
index 0000000..4497d40
--- /dev/null
+++ b/tests/builders/fixtures/build-publish-docker-image-minimal.yaml
@@ -0,0 +1,2 @@
1builders:
2 - build-publish-docker-image