Skip to content

Commit

Permalink
JENKINS-28443
Browse files Browse the repository at this point in the history
Added AWS Lambda post build action

awaiting testing for Lambda invocation
  • Loading branch information
cast committed May 23, 2015
1 parent 0d68c97 commit 8efb77a
Show file tree
Hide file tree
Showing 26 changed files with 1,115 additions and 178 deletions.
Expand Up @@ -26,7 +26,9 @@
* #L%
*/

import com.xti.jenkins.plugin.awslambda.upload.LambdaUploadAction;
import com.xti.jenkins.plugin.awslambda.upload.LambdaUploader;
import com.xti.jenkins.plugin.awslambda.upload.UploadConfig;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
Expand Down Expand Up @@ -83,15 +85,16 @@ public boolean perform(LambdaVariables lambdaVariables,AbstractBuild<?, ?> build
}
try {
LambdaVariables executionVariables = lambdaVariables.getClone();

executionVariables.expandVariables(build.getEnvironment(listener));
LambdaUploader lambdaUploader = new LambdaUploader(executionVariables, build, listener);
UploadConfig uploadConfig = executionVariables.getUploadConfig();

LambdaUploader lambdaUploader = new LambdaUploader(uploadConfig, build, listener);

Boolean lambdaSuccess = lambdaUploader.upload();
if(!lambdaSuccess){
build.setResult(Result.FAILURE);
}
build.addAction(new LambdaProminentAction(executionVariables.getFunctionName(), lambdaSuccess));
build.addAction(new LambdaUploadAction(executionVariables.getFunctionName(), lambdaSuccess));
return true;
} catch (Exception exc) {
throw new RuntimeException(exc);
Expand Down Expand Up @@ -135,7 +138,7 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
* This human readable name is used in the configuration screen.
*/
public String getDisplayName() {
return "Deploy into Lambda";
return "AWS Lambda deployment";
}

@Override
Expand Down
Expand Up @@ -27,6 +27,7 @@
*/

import com.xti.jenkins.plugin.awslambda.upload.UpdateModeValue;
import com.xti.jenkins.plugin.awslambda.upload.UploadConfig;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Util;
Expand All @@ -36,6 +37,9 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

/**
* Describable containing Lambda post build action config, checking feasability of migrating it to upload package.
*/
public class LambdaVariables extends AbstractDescribableImpl<LambdaVariables> {
private String awsAccessKeyId;
private String awsSecretKey;
Expand Down Expand Up @@ -188,6 +192,10 @@ public LambdaVariables getClone(){
return new LambdaVariables(awsAccessKeyId, awsSecretKey, awsRegion, artifactLocation, description, functionName, handler, memorySize, role, runtime, timeout, successOnly, updateMode);
}

public UploadConfig getUploadConfig(){
return new UploadConfig(awsAccessKeyId, awsSecretKey, awsRegion, artifactLocation, description, functionName, handler, memorySize, role, runtime, timeout, successOnly, updateMode);
}

private String expand(String value, EnvVars env) {
return Util.replaceMacro(value.trim(), env);
}
Expand Down
@@ -0,0 +1,89 @@
package com.xti.jenkins.plugin.awslambda.invoke;

import java.util.List;

public class InvokeConfig {
private String awsAccessKeyId;
private String awsSecretKey;
private String awsRegion;
private String functionName;
private String payload;
private boolean synchronous;
private boolean successOnly;
private List<JsonParameter> jsonParameters;

public InvokeConfig(String awsAccessKeyId, String awsSecretKey, String awsRegion, String functionName, String payload, boolean synchronous, boolean successOnly, List<JsonParameter> jsonParameters) {
this.awsAccessKeyId = awsAccessKeyId;
this.awsSecretKey = awsSecretKey;
this.awsRegion = awsRegion;
this.functionName = functionName;
this.payload = payload;
this.synchronous = synchronous;
this.successOnly = successOnly;
this.jsonParameters = jsonParameters;
}

public String getAwsAccessKeyId() {
return awsAccessKeyId;
}

public void setAwsAccessKeyId(String awsAccessKeyId) {
this.awsAccessKeyId = awsAccessKeyId;
}

public String getAwsSecretKey() {
return awsSecretKey;
}

public void setAwsSecretKey(String awsSecretKey) {
this.awsSecretKey = awsSecretKey;
}

public String getAwsRegion() {
return awsRegion;
}

public void setAwsRegion(String awsRegion) {
this.awsRegion = awsRegion;
}

public String getFunctionName() {
return functionName;
}

public void setFunctionName(String functionName) {
this.functionName = functionName;
}

public String getPayload() {
return payload;
}

public void setPayload(String payload) {
this.payload = payload;
}

public boolean isSynchronous() {
return synchronous;
}

public void setSynchronous(boolean synchronous) {
this.synchronous = synchronous;
}

public boolean isSuccessOnly() {
return successOnly;
}

public void setSuccessOnly(boolean successOnly) {
this.successOnly = successOnly;
}

public List<JsonParameter> getJsonParameters() {
return jsonParameters;
}

public void setJsonParameters(List<JsonParameter> jsonParameters) {
this.jsonParameters = jsonParameters;
}
}
Expand Up @@ -26,16 +26,12 @@
* #L%
*/

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;

public class JsonParameter extends AbstractDescribableImpl<JsonParameter> {
private String envVarName;
private String jsonPath;

@DataBoundConstructor
public JsonParameter(String envVarName, String jsonPath) {
this.envVarName = envVarName;
this.jsonPath = jsonPath;
Expand All @@ -57,16 +53,4 @@ public void setJsonPath(String jsonPath) {
this.jsonPath = jsonPath;
}

@Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static class DescriptorImpl extends Descriptor<JsonParameter> {

/**
* This human readable name is used in the configuration screen.
*/
public String getDisplayName() {
return "Environment Variable";
}


}
}
@@ -0,0 +1,76 @@
package com.xti.jenkins.plugin.awslambda.invoke;

/*
* #%L
* AWS Lambda Upload Plugin
* %%
* Copyright (C) 2015 XT-i
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;

public class JsonParameterVariables extends AbstractDescribableImpl<JsonParameterVariables> {
private String envVarName;
private String jsonPath;

@DataBoundConstructor
public JsonParameterVariables(String envVarName, String jsonPath) {
this.envVarName = envVarName;
this.jsonPath = jsonPath;
}

public String getEnvVarName() {
return envVarName;
}

public String getJsonPath() {
return jsonPath;
}

public void setEnvVarName(String envVarName) {
this.envVarName = envVarName;
}

public void setJsonPath(String jsonPath) {
this.jsonPath = jsonPath;
}

public JsonParameter getJsonParameter(){
return new JsonParameter(envVarName, jsonPath);
}

@Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static class DescriptorImpl extends Descriptor<JsonParameterVariables> {

/**
* This human readable name is used in the configuration screen.
*/
public String getDisplayName() {
return "Environment Variable";
}


}
}
@@ -0,0 +1,71 @@
package com.xti.jenkins.plugin.awslambda.invoke;

/*
* #%L
* AWS Lambda Upload Plugin
* %%
* Copyright (C) 2015 XT-i
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/

import hudson.model.ProminentProjectAction;

public class LambdaInvokeAction implements ProminentProjectAction {

//Nothing to show, go to console for now
private static final String URL_NAME = "console";

private final String iconFileName;
private final String bigIconFileName;
private final String displayName;


public LambdaInvokeAction(String functionName, Boolean success) {
if(success){
iconFileName = "/plugin/aws-lambda/images/Lambda_24.png";
bigIconFileName = "/plugin/aws-lambda/images/Lambda_48.png";
displayName = "Invoked Lambda: " + functionName;
}else {
iconFileName = "/plugin/aws-lambda/images/Lambda_24_grey.png";
bigIconFileName = "/plugin/aws-lambda/images/Lambda_48_grey.png";
displayName = "Lambda Invocation Failure: " + functionName;
}
}

@Override
public String getIconFileName() {
return iconFileName;
}

public String getBigIconFileName() {
return bigIconFileName;
}

@Override
public String getDisplayName() {
return displayName;
}

@Override
public String getUrlName() {
return URL_NAME;
}
}

0 comments on commit 8efb77a

Please sign in to comment.