Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jenkins pipeline support by implementing SimpleBuildStep #74

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509</version>
<version>1.591</version>
<relativePath />
</parent>
<artifactId>xcode-plugin</artifactId>
Expand Down Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.5.1</version>
<version>2.0</version>
</dependency>
</dependencies>
<build>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/au/com/rayh/DeveloperProfileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import hudson.util.ArgumentListBuilder;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -162,7 +163,7 @@ public ListBoxModel doFillProfileIdItems(@AncestorInPath Item context) {
}
}

private static final class GetHomeDirectory implements Callable<FilePath,IOException> {
private static final class GetHomeDirectory extends MasterToSlaveCallable<FilePath,IOException> {
public FilePath call() throws IOException {
return new FilePath(new File(System.getProperty("user.home")));
}
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/au/com/rayh/XCodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.CopyOnWriteList;
import hudson.util.QuotedStringTokenizer;
import jenkins.tasks.SimpleBuildStep;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
Expand All @@ -58,7 +61,7 @@
/**
* @author Ray Hilton
*/
public class XCodeBuilder extends Builder {
public class XCodeBuilder extends Builder implements SimpleBuildStep {

private static final int SIGTERM = 143;

Expand Down Expand Up @@ -251,10 +254,17 @@ private Object readResolve() throws ObjectStreamException {
return this;
}

@Override
public void perform(Run<?, ?> build, FilePath filePath, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
_perform(build, filePath, launcher, build.getEnvironment(listener), listener);
}

@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
EnvVars envs = build.getEnvironment(listener);
FilePath projectRoot = build.getWorkspace();
return _perform(build, build.getWorkspace(), launcher, build.getEnvironment(listener), listener);
}

private boolean _perform(Run<?,?> build, FilePath projectRoot, Launcher launcher, EnvVars envs, TaskListener listener) throws InterruptedException, IOException {

// check that the configured tools exist
if (!new FilePath(projectRoot.getChannel(), getGlobalConfiguration().getXcodebuildPath()).exists()) {
Expand Down Expand Up @@ -311,7 +321,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
try {
// If not empty we use the Token Expansion to replace it
// https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin
symRootValue = TokenMacro.expandAll(build, listener, symRoot).trim();
symRootValue = TokenMacro.expandAll(build, projectRoot, listener, symRoot).trim();
} catch (MacroEvaluationException e) {
listener.error(Messages.XCodeBuilder_symRootMacroError(e.getMessage()));
return false;
Expand All @@ -322,7 +332,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
FilePath buildDirectory;
if (!StringUtils.isEmpty(configurationBuildDir)) {
try {
configurationBuildDirValue = TokenMacro.expandAll(build, listener, configurationBuildDir).trim();
configurationBuildDirValue = TokenMacro.expandAll(build, projectRoot, listener, configurationBuildDir).trim();
} catch (MacroEvaluationException e) {
listener.error(Messages.XCodeBuilder_configurationBuildDirMacroError(e.getMessage()));
return false;
Expand Down Expand Up @@ -397,7 +407,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
try {
// If not empty we use the Token Expansion to replace it
// https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin
cfBundleShortVersionString = TokenMacro.expandAll(build, listener, cfBundleShortVersionStringValue);
cfBundleShortVersionString = TokenMacro.expandAll(build, projectRoot, listener, cfBundleShortVersionStringValue);
listener.getLogger().println(Messages.XCodeBuilder_CFBundleShortVersionStringUpdate(cfBundleShortVersionString));
returnCode = launcher.launch().envs(envs).cmds(getGlobalConfiguration().getAgvtoolPath(), "new-marketing-version", cfBundleShortVersionString).stdout(listener).pwd(projectRoot).join();
if (returnCode > 0) {
Expand All @@ -416,7 +426,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
try {
// If not empty we use the Token Expansion to replace it
// https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin
cfBundleVersion = TokenMacro.expandAll(build, listener, cfBundleVersionValue);
cfBundleVersion = TokenMacro.expandAll(build, projectRoot, listener, cfBundleVersionValue);
listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionUpdate(cfBundleVersion));
returnCode = launcher.launch().envs(envs).cmds(getGlobalConfiguration().getAgvtoolPath(), "new-version", "-all", cfBundleVersion).stdout(listener).pwd(projectRoot).join();
if (returnCode > 0) {
Expand Down