Browse Source

Merge "Add support for "Build / Publish Docker Image""

tags/2.10.0
Zuul 4 months ago
parent
commit
b1499530db

+ 60
- 0
jenkins_jobs/modules/builders.py View File

@@ -3958,6 +3958,66 @@ def description_setter(registry, xml_parent, data):
3958 3958
         descriptionsetter, data, mapping, fail_required=True)
3959 3959
 
3960 3960
 
3961
+def 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
+
3961 4021
 def docker_build_publish(parse, xml_parent, data):
3962 4022
     """yaml: docker-build-publish
3963 4023
     Requires the Jenkins :jenkins-wiki:`Docker build publish Plugin

+ 19
- 0
tests/builders/fixtures/build-publish-docker-image-full.xml View File

@@ -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>

+ 10
- 0
tests/builders/fixtures/build-publish-docker-image-full.yaml View File

@@ -0,0 +1,10 @@
1
+builders:
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

+ 19
- 0
tests/builders/fixtures/build-publish-docker-image-minimal.xml View File

@@ -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>

+ 2
- 0
tests/builders/fixtures/build-publish-docker-image-minimal.yaml View File

@@ -0,0 +1,2 @@
1
+builders:
2
+  - build-publish-docker-image

Loading…
Cancel
Save