Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #109 from vkravets/master
Browse files Browse the repository at this point in the history
Possible fix fo JENKINS-15758. Add ability to update tag.
  • Loading branch information
ndeloof committed Nov 9, 2012
2 parents 17132ba + d2f9499 commit 58516ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
40 changes: 19 additions & 21 deletions src/main/java/hudson/plugins/git/GitPublisher.java
@@ -1,21 +1,12 @@
package hudson.plugins.git;

import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.*;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixAggregatable;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.AbstractDescribableImpl;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Result;
import hudson.model.*;
import hudson.plugins.git.opt.PreBuildMergeOptions;
import hudson.remoting.VirtualChannel;
import hudson.scm.SCM;
Expand All @@ -24,19 +15,20 @@
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import hudson.util.FormValidation;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.RemoteConfig;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class GitPublisher extends Recorder implements Serializable, MatrixAggregatable {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -281,8 +273,8 @@ public Boolean invoke(File workspace,
return false;
}

if (t.isCreateTag()) {
if (git.tagExists(tagName)) {
if (t.isCreateTag() || t.isUpdateTag()) {
if (git.tagExists(tagName) && !t.isUpdateTag()) {
listener.getLogger().println("Tag " + tagName + " already exists and Create Tag is specified, so failing.");
return false;
}
Expand All @@ -297,7 +289,7 @@ else if (!git.tagExists(tagName)) {
listener.getLogger().println("Tag " + tagName + " does not exist and Create Tag is not specified, so failing.");
return false;
}

listener.getLogger().println("Pushing tag " + tagName + " to repo "
+ targetRepo);
git.push(remote, tagName);
Expand Down Expand Up @@ -589,6 +581,7 @@ public static final class TagToPush extends PushConfig {
private String tagName;
private String tagMessage;
private boolean createTag;
private boolean updateTag;

public String getTagName() {
return tagName;
Expand All @@ -602,12 +595,17 @@ public boolean isCreateTag() {
return createTag;
}

public boolean isUpdateTag() {
return updateTag;
}

@DataBoundConstructor
public TagToPush(String targetRepoName, String tagName, String tagMessage, boolean createTag) {
public TagToPush(String targetRepoName, String tagName, String tagMessage, boolean createTag, boolean updateTag) {
super(targetRepoName);
this.tagName = Util.fixEmptyAndTrim(tagName);
this.tagMessage = tagMessage;
this.createTag = createTag;
this.updateTag = updateTag;
}

@Extension
Expand Down
Expand Up @@ -42,6 +42,10 @@
title="${%Create new tag}">
<f:checkbox />
</f:entry>
<f:entry field="updateTag"
title="${%Update new tag}">
<f:checkbox />
</f:entry>
<f:entry field="targetRepoName"
title="${%Target remote name}">
<f:textbox
Expand Down
@@ -1,6 +1,6 @@
<div>
Specify tags to push at the completion of the build.<br/>
If the "Create Tag" option is selected, the tag will be created and pushed at the completion
If the "Create Tag" or "Update tag" option is selected, the tag will be created or updated and pushed at the completion
of the build, and the push will fail if a tag with the given name already exists. If the "Create Tag"
option is not selected, the push will fail if the tag does not already exist.<br/>
Environment variables may be used in the tag name - they will be replaced at build time.<br/>
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/hudson/plugins/git/GitPublisherTest.java
Expand Up @@ -31,10 +31,9 @@
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.plugins.git.GitPublisher.BranchToPush;
import hudson.plugins.git.GitPublisher.TagToPush;
import hudson.plugins.git.GitPublisher.NoteToPush;
import hudson.plugins.git.GitPublisher.TagToPush;
import hudson.scm.NullSCM;
import hudson.tasks.BuildStepDescriptor;
import org.jvnet.hudson.test.Bug;
Expand All @@ -57,7 +56,7 @@ public void testMatrixBuild() throws Exception {
mp.setAxes(new AxisList(new Axis("VAR","a","b")));
mp.setScm(new GitSCM(workDir.getAbsolutePath()));
mp.getPublishersList().add(new GitPublisher(
Collections.singletonList(new TagToPush("origin","foo","message",true)),
Collections.singletonList(new TagToPush("origin","foo","message",true, false)),
Collections.<BranchToPush>emptyList(),
Collections.<NoteToPush>emptyList(),
true, true) {
Expand Down

0 comments on commit 58516ae

Please sign in to comment.