Skip to content

Commit

Permalink
Adding support for multitag
Browse files Browse the repository at this point in the history
  • Loading branch information
jupierce committed Oct 4, 2016
1 parent a7ab069 commit 1b6e932
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 175 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,31 @@ b) "waitTime": The amount of time in milliseconds to see whether the specified

The step name is "openshiftTag". Mandatory parameters are:

a) "sourceStream" or "srcStream": The ImageStream of the existing image.
- "sourceStream" or "srcStream": The ImageStream of the existing image.

b) "sourceTag" or "srcTag": The tag (ImageStreamTag type) or ID (ImageStreamImage type) of the existing image.
- "sourceTag" or "srcTag": The tag (ImageStreamTag type) or ID (ImageStreamImage type) of the existing image.

c) "destinationStream" or "destStream": The ImageStream for the new tag.
- "destinationStream" or "destStream": The ImageStream for the new tag. A comma delimited list can be specified.

d) "destinationTag" or "destTag": The name of the new tag.
- "destinationTag" or "destTag": The name of the new tag. A comma delimited list can be specified.

The following combinations are supported:
1. 1 destination stream and 1 destination tag (i.e. single tag applies to single stream)
- `destinationStream: 'stream1', destinationTag: 'tag1'`
1. 1 destination stream and N destination tags (i.e. all tags apply to the same stream)
- `destinationStream: 'stream1', destinationTag: 'tag1, tag2'`
1. 1 destination tag and N destination streams (i.e. all streams will get the same tag)
- `destinationStream: 'stream1, stream2', destinationTag: 'tag1'`
1. N destination streams and N destination tags (i.e. each index will be combined to form a unique stream:tag combination)
- `destinationStream: 'stream1, stream2', destinationTag: 'tag1, tag2'`

Optional parameters are:

a) "alias": Whether to update destination tag whenever the source tag changes. Equivalent of the `--alias` option for the `oc tag` command. When false, the destination tag type is "ImageStreamImage", and when true, the destination tag type is "ImageStreamTag".
- "alias": Whether to update destination tag whenever the source tag changes. Equivalent of the `--alias` option for the `oc tag` command. When false, the destination tag type is "ImageStreamImage", and when true, the destination tag type is "ImageStreamTag".

b) "destinationNamespace": The name of the project to host the destinationStream:destinationTag. If nothing is specified, the plugin will inspect the PROJECT_NAME environment variable.
- "destinationNamespace": The name of the project to host the destinationStream:destinationTag. If nothing is specified, the plugin will use the source namespace.

c) "destinationAuthToken": The authorization token for interacting with the destinationNamespace. If you do not supply a value, the plugin will assume it is running in the OpenShift Jenkins image and attempt to load the kubernetes service account token stored in that image.
- "destinationAuthToken": The authorization token for interacting with the destinationNamespace. If you do not supply a value, the plugin will assume it is running in the OpenShift Jenkins image and attempt to load the kubernetes service account token stored in that image.

#### "Verify OpenShift Build"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class MessageConstants {
/*
* These messages are for the "Tag OpenShift Image" jenkins build step implemented by OpenShiftImageTagger
*/
public static final String START_TAG = "\n\nStarting \"" + OpenShiftImageTagger.DISPLAY_NAME + "\" with the source [image stream:tag] \"%s:%s\" from the project \"%s\" and destination [image stream:tag] \"%s:%s\" from the project \"%s\".";
public static final String START_TAG = "\n\nStarting \"" + OpenShiftImageTagger.DISPLAY_NAME + "\" with the source [image stream:tag] \"%s:%s\" from the project \"%s\" and destination stream(s) \"%s\" with tag(s) \"%s\" from the project \"%s\".";
public static final String EXIT_TAG_CANNOT_CREATE_DEST_IS = "\n\nExiting \"" + OpenShiftImageTagger.DISPLAY_NAME + "\" unsuccessfully; could not create the image stream \"%s\" in the project \"%s\".";
public static final String EXIT_TAG_CANNOT_GET_IS = "\n\nExiting \"" + OpenShiftImageTagger.DISPLAY_NAME + "\" unsuccessfully; could not retrieve the image stream \"%s\" from the project \"%s\".";
public static final String EXIT_TAG_NOT_FOUND = "\n\nExisting \"" + OpenShiftImageTagger.DISPLAY_NAME + "\" unsuccessfully; could not fine either an image tag or ID \"%s\" associated with the image stream \"%s\".";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.openshift.jenkins.plugins.pipeline;

import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftImageTagger;
import hudson.Extension;
import hudson.util.FormValidation;
import hudson.model.AbstractProject;
import hudson.tasks.Builder;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.QueryParameter;

import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftImageTagger;
//import com.openshift.restclient.authorization.TokenAuthorizationStrategy;

import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;

import java.io.IOException;
//import java.util.Map;

public class OpenShiftImageTagger extends OpenShiftBaseStep implements IOpenShiftImageTagger {

Expand All @@ -29,9 +24,7 @@ public class OpenShiftImageTagger extends OpenShiftBaseStep implements IOpenShif
protected final String destinationNamespace;
protected final String destinationAuthToken;
protected final String alias;
// marked transient so don't serialize these next 2 in the workflow plugin flow; constructed on per request basis
// protected transient TokenAuthorizationStrategy destinationBearerToken;


// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
@DataBoundConstructor
public OpenShiftImageTagger(String apiURL, String testTag, String prodTag, String namespace, String authToken, String verbose, String testStream, String prodStream, String destinationNamespace, String destinationAuthToken, String alias) {
Expand All @@ -54,19 +47,39 @@ public String getAlias() {
return alias;
}

public String getTestTag() {
@Deprecated
public String getTestTag() {
return testTag;
}

public String getSrcTag() {
return testTag;
}

public String getProdTag() {
return prodTag;
@Deprecated
public String getProdTag() {
return prodTag;
}

public String getDestTag() {
return prodTag;
}

public String getTestStream() {

@Deprecated
public String getTestStream() {
return testStream;
}

public String getSrcStream() {
return testStream;
}

public String getProdStream() {
@Deprecated
public String getProdStream() {
return prodStream;
}

public String getDestStream() {
return prodStream;
}

Expand All @@ -78,15 +91,6 @@ public String getDestinationAuthToken() {
return this.destinationAuthToken;
}

/* public TokenAuthorizationStrategy getDestinationToken() {
return destinationBearerToken;
}
public void setDestinationToken(TokenAuthorizationStrategy token) {
destinationBearerToken = token;
}
*/

// Overridden for better type safety.
// If your plugin doesn't really define any property on Descriptor,
// you don't have to do this.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.openshift.jenkins.plugins.pipeline.dsl;
import com.openshift.jenkins.plugins.pipeline.ParamVerify;
import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftImageTagger;
import hudson.Extension;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepMonitor;

import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import com.openshift.jenkins.plugins.pipeline.ParamVerify;
import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftImageTagger;
//import com.openshift.restclient.authorization.TokenAuthorizationStrategy;

import java.util.Collection;
import java.util.Map;
import java.util.logging.Logger;


public class OpenShiftImageTagger extends OpenShiftBaseStep implements IOpenShiftImageTagger {

Expand All @@ -30,9 +25,7 @@ public class OpenShiftImageTagger extends OpenShiftBaseStep implements IOpenShif
protected String destinationNamespace;
protected String destinationAuthToken;
protected String alias;
// marked transient so don't serialize these next 2 in the workflow plugin flow; constructed on per request basis
//protected transient TokenAuthorizationStrategy destinationBearerToken;


// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
@DataBoundConstructor
public OpenShiftImageTagger(String srcStream, String srcTag, String destStream, String destTag) {
Expand Down Expand Up @@ -107,19 +100,6 @@ public String getDestinationAuthToken() {
this.destinationAuthToken = destinationAuthToken;
}

/* public TokenAuthorizationStrategy getDestinationToken() {
return destinationBearerToken;
}
public void setDestinationToken(TokenAuthorizationStrategy token) {
destinationBearerToken = token;
}
*/


private static final Logger LOGGER = Logger.getLogger(OpenShiftImageTagger.class.getName());


@Extension
public static class DescriptorImpl extends AbstractStepDescriptorImpl {

Expand Down
Loading

0 comments on commit 1b6e932

Please sign in to comment.