├── src ├── main │ ├── resources │ │ ├── com │ │ │ └── xti │ │ │ │ └── jenkins │ │ │ │ └── plugin │ │ │ │ └── awslambda │ │ │ │ ├── tags │ │ │ │ ├── taglib │ │ │ │ └── awsLambdaOptionalBlock.jelly │ │ │ │ ├── invoke │ │ │ │ ├── LambdaInvokeAction │ │ │ │ │ └── summary.jelly │ │ │ │ ├── JsonParameterVariables │ │ │ │ │ └── config.jelly │ │ │ │ ├── LambdaInvokeBuildStep │ │ │ │ │ └── config.jelly │ │ │ │ ├── LambdaInvokeBuildStepVariables │ │ │ │ │ └── config.jelly │ │ │ │ └── LambdaInvokePublisher │ │ │ │ │ └── config.jelly │ │ │ │ ├── publish │ │ │ │ ├── LambdaPublishAction │ │ │ │ │ └── summary.jelly │ │ │ │ ├── LambdaPublishBuildStep │ │ │ │ │ └── config.jelly │ │ │ │ ├── LambdaPublishPublisher │ │ │ │ │ └── config.jelly │ │ │ │ └── LambdaPublishBuildStepVariables │ │ │ │ │ └── config.jelly │ │ │ │ ├── upload │ │ │ │ ├── LambdaUploadAction │ │ │ │ │ └── summary.jelly │ │ │ │ ├── LambdaUploadBuildStep │ │ │ │ │ └── config.jelly │ │ │ │ ├── EnvironmentEntry │ │ │ │ │ └── config.jelly │ │ │ │ ├── EnvironmentConfiguration │ │ │ │ │ └── config.jelly │ │ │ │ ├── LambdaUploadBuildStepVariables │ │ │ │ │ └── config.jelly │ │ │ │ └── LambdaUploadVariables │ │ │ │ │ └── config.jelly │ │ │ │ └── eventsource │ │ │ │ ├── LambdaEventSourceAction │ │ │ │ └── summary.jelly │ │ │ │ ├── LambdaEventSourceBuildStep │ │ │ │ └── config.jelly │ │ │ │ ├── LambdaEventSourceBuildStepVariables │ │ │ │ └── config.jelly │ │ │ │ └── LambdaEventSourcePublisher │ │ │ │ └── config.jelly │ │ └── index.jelly │ ├── webapp │ │ ├── help-eventSourceArn.html │ │ ├── images │ │ │ ├── Lambda_24.png │ │ │ ├── Lambda_48.png │ │ │ ├── Lambda_24_grey.png │ │ │ ├── Lambda_48_grey.png │ │ │ └── Lambda.svg │ │ ├── help-awsSecretKey.html │ │ ├── help-awsAccessKeyId.html │ │ ├── help-kmsArn.html │ │ ├── help-description.html │ │ ├── help-payload.html │ │ ├── help-memorySize.html │ │ ├── help-runtime.html │ │ ├── help-functionAlias.html │ │ ├── help-alias.html │ │ ├── help-envVarName.html │ │ ├── help-role.html │ │ ├── help-timeout.html │ │ ├── help-functionName.html │ │ ├── help-updateMode.html │ │ ├── help-functionARN.html │ │ ├── help-useInstanceCredentials.html │ │ ├── help-versionDescription.html │ │ ├── help-synchronous.html │ │ ├── help-handler.html │ │ ├── help-publishNewVersion.html │ │ ├── help-deadletterqueue.html │ │ ├── help-successOnly.html │ │ ├── help-assignAlias.html │ │ ├── help-artifactLocation.html │ │ ├── help-subnets.html │ │ ├── help-securityGroups.html │ │ ├── help-awsRegion.html │ │ ├── help-jsonPath.html │ │ └── js │ │ │ └── awslambda.js │ └── java │ │ └── com │ │ └── xti │ │ └── jenkins │ │ └── plugin │ │ └── awslambda │ │ ├── exception │ │ ├── LambdaInvokeException.java │ │ ├── AWSLambdaPluginException.java │ │ └── LambdaDeployException.java │ │ ├── invoke │ │ ├── AWSInvokeDescriptor.java │ │ ├── LambdaInvocationResult.java │ │ ├── LambdaOutputInjectionAction.java │ │ ├── InvokeConfig.java │ │ ├── JsonParameter.java │ │ ├── LambdaInvokeAction.java │ │ ├── LambdaInvoker.java │ │ └── JsonParameterVariables.java │ │ ├── eventsource │ │ ├── AWSEventSourceDescriptor.java │ │ ├── EventSourceBuilder.java │ │ ├── LambdaEventSourceAction.java │ │ ├── EventSourceConfig.java │ │ └── LambdaEventSourcePublisher.java │ │ ├── util │ │ ├── ExpansionUtils.java │ │ ├── JenkinsProxy.java │ │ ├── LogUtils.java │ │ ├── Tokenizer.java │ │ └── LambdaClientConfig.java │ │ ├── service │ │ ├── JenkinsLogger.java │ │ ├── DeployResult.java │ │ ├── PublishResult.java │ │ ├── AliasResult.java │ │ ├── JsonPathParser.java │ │ ├── WorkSpaceZipper.java │ │ ├── LambdaPublishService.java │ │ └── LambdaInvokeService.java │ │ ├── publish │ │ ├── LambdaPublishServiceResponse.java │ │ ├── LambdaPublisher.java │ │ ├── PublishConfig.java │ │ ├── LambdaPublishAction.java │ │ ├── LambdaPublishPublisher.java │ │ └── LambdaPublishBuildStep.java │ │ ├── upload │ │ ├── UpdateModeValue.java │ │ ├── EnvironmentEntry.java │ │ ├── AliasConfig.java │ │ ├── LambdaUploader.java │ │ ├── LambdaUploadAction.java │ │ └── EnvironmentConfiguration.java │ │ ├── callable │ │ ├── EventSourceCallable.java │ │ ├── PublishCallable.java │ │ ├── DeployCallable.java │ │ └── InvokeCallable.java │ │ └── AWSLambdaDescriptor.java └── test │ ├── resources │ ├── echo.zip │ └── echo │ │ └── index.js │ └── java │ └── com │ └── xti │ └── jenkins │ └── plugin │ └── awslambda │ ├── util │ ├── ExpansionUtilsTest.java │ ├── LogUtilsTest.java │ └── TokenizerTest.java │ ├── TestUtil.java │ ├── service │ ├── LambdaClientConfigTest.java │ └── JenkinsLoggerTest.java │ ├── invoke │ ├── LambdaInvokeActionTest.java │ ├── LambdaInvokerTest.java │ └── LambdaInvokeVariablesTest.java │ ├── upload │ ├── LambdaUploadActionTest.java │ └── LambdaUploaderTest.java │ └── publish │ ├── LambdaPublishActionTest.java │ ├── LambdaPublishTest.java │ ├── LambdaPublishVariablesTest.java │ ├── LambdaPublishBuildStepVariablesTest.java │ └── LambdaPublishPublisherTest.java ├── blogpost ├── deploy.jpg ├── deploy.png ├── install.jpg ├── install.png ├── invoke.jpg ├── invoke.png ├── result.jpg ├── result.png ├── build-step.jpg ├── build-step.png ├── post-build.jpg ├── post-build.png ├── invoke-json-parameters.jpg └── invoke-json-parameters.png ├── img ├── build-step-config.png └── pipeline-syntax.png ├── LICENSE.txt ├── .gitignore ├── CHANGELOG.md └── pom.xml /src/main/resources/com/xti/jenkins/plugin/awslambda/tags/taglib: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /blogpost/deploy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/deploy.jpg -------------------------------------------------------------------------------- /blogpost/deploy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/deploy.png -------------------------------------------------------------------------------- /blogpost/install.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/install.jpg -------------------------------------------------------------------------------- /blogpost/install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/install.png -------------------------------------------------------------------------------- /blogpost/invoke.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/invoke.jpg -------------------------------------------------------------------------------- /blogpost/invoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/invoke.png -------------------------------------------------------------------------------- /blogpost/result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/result.jpg -------------------------------------------------------------------------------- /blogpost/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/result.png -------------------------------------------------------------------------------- /src/main/webapp/help-eventSourceArn.html: -------------------------------------------------------------------------------- 1 |
2 | The ARN of the event source to map to 3 |
-------------------------------------------------------------------------------- /blogpost/build-step.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/build-step.jpg -------------------------------------------------------------------------------- /blogpost/build-step.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/build-step.png -------------------------------------------------------------------------------- /blogpost/post-build.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/post-build.jpg -------------------------------------------------------------------------------- /blogpost/post-build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/post-build.png -------------------------------------------------------------------------------- /img/build-step-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/img/build-step-config.png -------------------------------------------------------------------------------- /img/pipeline-syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/img/pipeline-syntax.png -------------------------------------------------------------------------------- /src/test/resources/echo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/src/test/resources/echo.zip -------------------------------------------------------------------------------- /blogpost/invoke-json-parameters.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/invoke-json-parameters.jpg -------------------------------------------------------------------------------- /blogpost/invoke-json-parameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/blogpost/invoke-json-parameters.png -------------------------------------------------------------------------------- /src/main/webapp/images/Lambda_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/src/main/webapp/images/Lambda_24.png -------------------------------------------------------------------------------- /src/main/webapp/images/Lambda_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/src/main/webapp/images/Lambda_48.png -------------------------------------------------------------------------------- /src/main/webapp/images/Lambda_24_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/src/main/webapp/images/Lambda_24_grey.png -------------------------------------------------------------------------------- /src/main/webapp/images/Lambda_48_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/aws-lambda-plugin/HEAD/src/main/webapp/images/Lambda_48_grey.png -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 4 |
5 | This Plugin allows you to upload a zip file or folder to AWS Lambda 6 |
7 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/exception/LambdaInvokeException.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.exception; 2 | 3 | public class LambdaInvokeException extends AWSLambdaPluginException { 4 | public LambdaInvokeException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 3 | 4 | ${it.displayName} 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 3 | 4 | ${it.displayName} 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 3 | 4 | ${it.displayName} 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourceAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 3 | 4 | ${it.displayName} 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/AWSInvokeDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import com.xti.jenkins.plugin.awslambda.AWSLambdaDescriptor; 4 | import hudson.model.Describable; 5 | 6 | public abstract class AWSInvokeDescriptor> extends AWSLambdaDescriptor { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadBuildStep/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/test/resources/echo/index.js: -------------------------------------------------------------------------------- 1 | console.log('Loading function'); 2 | 3 | exports.handler = function(event, context) { 4 | console.log('value1 =', event.key1); 5 | if(event.key1 == 'moon'){ 6 | context.fail('event_fail'); 7 | }else{ 8 | event.key1 = 'hello ' + event.key1; 9 | context.succeed(event); 10 | } 11 | }; -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/AWSEventSourceDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.eventsource; 2 | 3 | import com.xti.jenkins.plugin.awslambda.AWSLambdaDescriptor; 4 | import hudson.model.Describable; 5 | 6 | /** 7 | * Created by anthonyikeda on 25/11/2015. 8 | */ 9 | public abstract class AWSEventSourceDescriptor> extends AWSLambdaDescriptor { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/exception/AWSLambdaPluginException.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.exception; 2 | 3 | public class AWSLambdaPluginException extends RuntimeException { 4 | public AWSLambdaPluginException(String message) { 5 | super(message); 6 | } 7 | 8 | public AWSLambdaPluginException(String message, Throwable cause) { 9 | super(message, cause); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/exception/LambdaDeployException.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.exception; 2 | 3 | public class LambdaDeployException extends AWSLambdaPluginException { 4 | 5 | public LambdaDeployException(String message) { 6 | super(message); 7 | } 8 | 9 | public LambdaDeployException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/util/ExpansionUtils.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import hudson.EnvVars; 4 | import hudson.Util; 5 | 6 | public class ExpansionUtils { 7 | 8 | public static String expand(String value, EnvVars env) { 9 | if(value != null) { 10 | return Util.replaceMacro(value.trim(), env); 11 | } else { 12 | return null; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/util/JenkinsProxy.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import hudson.ProxyConfiguration; 4 | import jenkins.model.Jenkins; 5 | 6 | public class JenkinsProxy { 7 | public static ProxyConfiguration getConfig(){ 8 | Jenkins instance = Jenkins.getInstance(); 9 | 10 | if (instance != null) { 11 | return instance.proxy; 12 | } else { 13 | return null; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/JenkinsLogger.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class JenkinsLogger { 6 | private PrintStream logStream; 7 | 8 | public JenkinsLogger(PrintStream logStream) { 9 | this.logStream = logStream; 10 | } 11 | 12 | public void log(String mask, Object... args) { 13 | if(mask != null) { 14 | logStream.println(String.format(mask, args)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/EnvironmentEntry/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/util/ExpansionUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import hudson.EnvVars; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class ExpansionUtilsTest { 9 | 10 | @Test 11 | public void expansionTest(){ 12 | EnvVars envVars = new EnvVars(); 13 | envVars.put("ENV_ID", "ID"); 14 | assertEquals("ID", ExpansionUtils.expand("${ENV_ID}", envVars)); 15 | assertEquals("ID", ExpansionUtils.expand("$ENV_ID", envVars)); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/invoke/JsonParameterVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/util/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | 6 | public class LogUtils { 7 | public static String getStackTrace(Throwable t){ 8 | StringWriter sw = new StringWriter(); 9 | PrintWriter pw = new PrintWriter(sw); 10 | t.printStackTrace(pw); 11 | String stackTrace = sw.toString(); 12 | pw.close(); 13 | try{ 14 | sw.close(); 15 | }catch(Exception ignored){ 16 | } 17 | return stackTrace; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvocationResult.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | public class LambdaInvocationResult implements Serializable { 7 | private boolean success; 8 | private Map injectables; 9 | 10 | public LambdaInvocationResult(boolean success, Map injectables) { 11 | this.success = success; 12 | this.injectables = injectables; 13 | } 14 | 15 | public boolean isSuccess() { 16 | return success; 17 | } 18 | 19 | public Map getInjectables() { 20 | return injectables; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/EnvironmentConfiguration/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/EventSourceBuilder.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.eventsource; 2 | 3 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 4 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 5 | 6 | /** 7 | * Created by anthonyikeda on 25/11/2015. 8 | */ 9 | public class EventSourceBuilder { 10 | 11 | private LambdaDeployService lambda; 12 | 13 | private JenkinsLogger logger; 14 | 15 | public EventSourceBuilder(LambdaDeployService lambda, JenkinsLogger logger) { 16 | this.lambda = lambda; 17 | this.logger = logger; 18 | } 19 | 20 | public Boolean createEventSource(EventSourceConfig config) { 21 | 22 | return lambda.deployEventSource(config); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/util/LogUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import com.amazonaws.AmazonClientException; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class LogUtilsTest { 9 | 10 | @Test 11 | public void testGetStackTrace() throws Exception { 12 | try { 13 | throw new AmazonClientException("something wrong"); 14 | } catch (AmazonClientException ace){ 15 | String stackTrace = LogUtils.getStackTrace(ace); 16 | assertTrue(stackTrace.startsWith("com.amazonaws.AmazonClientException: something wrong")); 17 | assertTrue(stackTrace.contains("at com.xti.jenkins.plugin.awslambda.util.LogUtilsTest.testGetStackTrace")); } 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishServiceResponse.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | /** 4 | * Created by sulland on 27/07/16. 5 | */ 6 | public class LambdaPublishServiceResponse { 7 | private String functionVersion; 8 | private String functionAlias; 9 | private boolean success; 10 | 11 | public LambdaPublishServiceResponse(String functionVersion, String functionAlias, boolean success){ 12 | this.functionAlias = functionAlias; 13 | this.functionVersion = functionVersion; 14 | this.success = success; 15 | } 16 | 17 | public String getFunctionVersion(){ 18 | return this.functionVersion; 19 | } 20 | 21 | public String getFunctionAlias(){ 22 | return this.functionAlias; 23 | } 24 | 25 | public boolean getSuccess(){ 26 | return this.success; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/util/Tokenizer.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | 10 | /** 11 | * Project: aws-lambda 12 | * Created by Michael Willemse on 12/02/2016. 13 | */ 14 | public class Tokenizer { 15 | 16 | public static List split(String input){ 17 | if(input == null){ 18 | return new ArrayList<>(); 19 | } 20 | List tokens = new ArrayList<>(Arrays.asList(input.replaceAll("^[,\\s]+", "").split("[,\\s]+"))); 21 | 22 | Iterator tokenIterator = tokens.iterator(); 23 | while (tokenIterator.hasNext()){ 24 | String token = tokenIterator.next(); 25 | if(StringUtils.isBlank(token)){ 26 | tokenIterator.remove(); 27 | } 28 | } 29 | 30 | return tokens; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/TestUtil.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.net.URL; 8 | 9 | public class TestUtil { 10 | public File getResource(String resourcePath){ 11 | ClassLoader classLoader = getClass().getClassLoader(); 12 | URL resource = classLoader.getResource(resourcePath); 13 | if(resource != null){ 14 | try { 15 | File tempEcho = File.createTempFile("aws-lambda-plugin", "echo.zip"); 16 | FileUtils.copyFile(new File(resource.getFile()), tempEcho); 17 | tempEcho.deleteOnExit(); 18 | return tempEcho; 19 | } catch (IOException e) { 20 | throw new IllegalStateException("Could not load " + resourcePath); 21 | } 22 | 23 | } else { 24 | throw new IllegalStateException("Could not load " + resourcePath); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/UpdateModeValue.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | public enum UpdateModeValue { 6 | Full("full", "Code and configuration"), Code("code", "Code"), Config("config", "Configuration"); 7 | 8 | private String mode; 9 | private String displayName; 10 | 11 | UpdateModeValue(String mode, String display) { 12 | this.mode = mode; 13 | this.displayName = display; 14 | } 15 | 16 | public String getMode() { 17 | return mode; 18 | } 19 | 20 | public String getDisplayName() { 21 | return displayName; 22 | } 23 | 24 | public static UpdateModeValue fromString(String mode){ 25 | if(StringUtils.isEmpty(mode)){ 26 | return Full; 27 | } 28 | 29 | if(Code.mode.equals(mode)){ 30 | return Code; 31 | } 32 | 33 | if(Config.mode.equals(mode)){ 34 | return Config; 35 | } 36 | 37 | return Full; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaOutputInjectionAction.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import hudson.EnvVars; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.EnvironmentContributingAction; 6 | 7 | public class LambdaOutputInjectionAction implements EnvironmentContributingAction { 8 | 9 | private String key; 10 | private String value; 11 | 12 | public LambdaOutputInjectionAction(String key, String value) { 13 | this.key = key; 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public void buildEnvVars(AbstractBuild build, EnvVars env) { 19 | if (env != null && key != null && value != null) { 20 | env.put(key, value); 21 | } 22 | } 23 | 24 | @Override 25 | public String getIconFileName() { 26 | return null; 27 | } 28 | 29 | @Override 30 | public String getDisplayName() { 31 | return "LambdaOutputInjectAction"; 32 | } 33 | 34 | @Override 35 | public String getUrlName() { 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/DeployResult.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | public class DeployResult { 4 | private boolean success; 5 | private String functionName; 6 | private String functionVersion; 7 | 8 | public DeployResult(boolean success, String functionName, String functionVersion) { 9 | this.success = success; 10 | this.functionName = functionName; 11 | this.functionVersion = functionVersion; 12 | } 13 | 14 | public boolean isSuccess() { 15 | return success; 16 | } 17 | 18 | public void setSuccess(boolean success) { 19 | this.success = success; 20 | } 21 | 22 | public String getFunctionName() { 23 | return functionName; 24 | } 25 | 26 | public void setFunctionName(String functionName) { 27 | this.functionName = functionName; 28 | } 29 | 30 | public String getFunctionVersion() { 31 | return functionVersion; 32 | } 33 | 34 | public void setFunctionVersion(String functionVersion) { 35 | this.functionVersion = functionVersion; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/service/LambdaClientConfigTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import com.xti.jenkins.plugin.awslambda.util.JenkinsProxy; 4 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | import static org.junit.Assert.fail; 9 | 10 | public class LambdaClientConfigTest { 11 | 12 | @Test 13 | public void testGetClient() throws Exception { 14 | LambdaClientConfig lambdaClientConfig = new LambdaClientConfig("abc", "def", "eu-west-1", JenkinsProxy.getConfig()); 15 | assertNotNull(lambdaClientConfig.getClient()); 16 | } 17 | 18 | @Test 19 | public void testGetClientInvalidRegion() throws Exception { 20 | try { 21 | LambdaClientConfig lambdaClientConfig = new LambdaClientConfig("abc", "def", "ghi", JenkinsProxy.getConfig()); 22 | lambdaClientConfig.getClient(); 23 | fail("Should have failed with IllegalArgumentException"); 24 | } catch (IllegalArgumentException ignored){ 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/PublishResult.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | public class PublishResult { 4 | private boolean success; 5 | private String functionName; 6 | private String functionVersion; 7 | 8 | public PublishResult(boolean success, String functionName, String functionVersion) { 9 | this.success = success; 10 | this.functionName = functionName; 11 | this.functionVersion = functionVersion; 12 | } 13 | 14 | public boolean isSuccess() { 15 | return success; 16 | } 17 | 18 | public void setSuccess(boolean success) { 19 | this.success = success; 20 | } 21 | 22 | public String getFunctionName() { 23 | return functionName; 24 | } 25 | 26 | public void setFunctionName(String functionName) { 27 | this.functionName = functionName; 28 | } 29 | 30 | public String getFunctionVersion() { 31 | return functionVersion; 32 | } 33 | 34 | public void setFunctionVersion(String functionVersion) { 35 | this.functionVersion = functionVersion; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublisher.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 4 | import com.xti.jenkins.plugin.awslambda.service.LambdaPublishService; 5 | import hudson.tasks.BuildStepMonitor; 6 | import hudson.tasks.Notifier; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * Project: aws-lambda 12 | * Created by Magnus Sulland on 26/07/2016. 13 | */ 14 | public class LambdaPublisher extends Notifier { 15 | private LambdaPublishService lambda; 16 | private JenkinsLogger logger; 17 | 18 | public LambdaPublisher(LambdaPublishService lambda, JenkinsLogger logger) throws IOException, InterruptedException { 19 | this.lambda = lambda; 20 | this.logger = logger; 21 | } 22 | 23 | public LambdaPublishServiceResponse publish(PublishConfig config) throws IOException, InterruptedException { 24 | logger.log("%nStarting lambda publish procedure"); 25 | return lambda.publishLambda(config); 26 | } 27 | 28 | public BuildStepMonitor getRequiredMonitorService() { 29 | return BuildStepMonitor.BUILD; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/main/webapp/help-awsSecretKey.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | AWS Secret Key 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-awsAccessKeyId.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | AWS Access Key Id 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-kmsArn.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | ARN of AWS KMS key 28 |
29 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/EnvironmentEntry.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import com.xti.jenkins.plugin.awslambda.util.ExpansionUtils; 4 | import hudson.EnvVars; 5 | import hudson.Extension; 6 | import hudson.model.AbstractDescribableImpl; 7 | import hudson.model.Descriptor; 8 | import org.kohsuke.stapler.DataBoundConstructor; 9 | 10 | public class EnvironmentEntry extends AbstractDescribableImpl { 11 | private String key; 12 | private String value; 13 | 14 | @DataBoundConstructor 15 | public EnvironmentEntry(String key, String value) { 16 | this.key = key; 17 | this.value = value; 18 | } 19 | 20 | public String getKey() { 21 | return key; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | 28 | public void expandVariables(EnvVars env) { 29 | key = ExpansionUtils.expand(key, env); 30 | value = ExpansionUtils.expand(value, env); 31 | } 32 | 33 | public EnvironmentEntry getClone(){ 34 | return new EnvironmentEntry(key, value); 35 | } 36 | 37 | @Extension 38 | public static class DescriptorImpl extends Descriptor { 39 | public String getDisplayName() { return ""; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/webapp/help-description.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Description (optional) 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-payload.html: -------------------------------------------------------------------------------- 1 | 26 |
27 |

Payload for to AWS Lambda invocation

28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-memorySize.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Memory Size (128 - 1024, increments of 64) 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-runtime.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Runtime (currently, "nodejs", "python2.7" or "java8") 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-functionAlias.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | The alias to be used for the newly published function 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-alias.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Name of the alias to be pointing to the new function version. 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-envVarName.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Name of Jenkins environment variable set by JsonPath expression 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-role.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Amazon Resource Name (arn) of IAM role used to execute Lambda function 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-timeout.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Function timeout setting in seconds (1 to 300, in 1 second increments) 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-functionName.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | AWS Lambda function name (Required, but for display in AWS console only) 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-updateMode.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | If a function does not exist, both configuration and code will be updated 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-functionARN.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | ARN to the lambda function the alias should point to the $LATEST version of. 28 |
29 | -------------------------------------------------------------------------------- /src/main/webapp/help-useInstanceCredentials.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Uses instance credentials such as IAM role, environment variables, system properties. 28 |
29 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeActionTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class LambdaInvokeActionTest { 8 | 9 | @Test 10 | public void testLambdaInvokeActionSuccess(){ 11 | LambdaInvokeAction lambdaInvokeAction = new LambdaInvokeAction("lambda1", true); 12 | 13 | assertEquals("Invoked Lambda: lambda1", lambdaInvokeAction.getDisplayName()); 14 | assertEquals("console", lambdaInvokeAction.getUrlName()); 15 | assertEquals("/plugin/aws-lambda/images/Lambda_24.png", lambdaInvokeAction.getIconFileName()); 16 | assertEquals("/plugin/aws-lambda/images/Lambda_48.png", lambdaInvokeAction.getBigIconFileName()); 17 | } 18 | 19 | @Test 20 | public void testLambdaInvokeActionFailure(){ 21 | LambdaInvokeAction lambdaInvokeAction = new LambdaInvokeAction("lambda1", false); 22 | 23 | assertEquals("Lambda invocation failure: lambda1", lambdaInvokeAction.getDisplayName()); 24 | assertEquals("console", lambdaInvokeAction.getUrlName()); 25 | assertEquals("/plugin/aws-lambda/images/Lambda_24_grey.png", lambdaInvokeAction.getIconFileName()); 26 | assertEquals("/plugin/aws-lambda/images/Lambda_48_grey.png", lambdaInvokeAction.getBigIconFileName()); 27 | } 28 | } -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadActionTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class LambdaUploadActionTest { 8 | 9 | @Test 10 | public void testLambdaUploadActionSuccess(){ 11 | LambdaUploadAction lambdaUploadAction = new LambdaUploadAction("lambda1", true); 12 | 13 | assertEquals("Deployed Lambda: lambda1", lambdaUploadAction.getDisplayName()); 14 | assertEquals("console", lambdaUploadAction.getUrlName()); 15 | assertEquals("/plugin/aws-lambda/images/Lambda_24.png", lambdaUploadAction.getIconFileName()); 16 | assertEquals("/plugin/aws-lambda/images/Lambda_48.png", lambdaUploadAction.getBigIconFileName()); 17 | } 18 | 19 | @Test 20 | public void testLambdaUploadActionFailure(){ 21 | LambdaUploadAction lambdaUploadAction = new LambdaUploadAction("lambda1", false); 22 | 23 | assertEquals("Lambda deployment failure: lambda1", lambdaUploadAction.getDisplayName()); 24 | assertEquals("console", lambdaUploadAction.getUrlName()); 25 | assertEquals("/plugin/aws-lambda/images/Lambda_24_grey.png", lambdaUploadAction.getIconFileName()); 26 | assertEquals("/plugin/aws-lambda/images/Lambda_48_grey.png", lambdaUploadAction.getBigIconFileName()); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/main/webapp/help-versionDescription.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | A description to be given to the version. Recommended is the build number and information from jenkins. 28 |
29 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/PublishConfig.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Project: aws-lambda 7 | * Created by Magnus Sulland on 26/07/2016. 8 | */ 9 | public class PublishConfig implements Serializable { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | private String functionAlias; 14 | private String functionARN; 15 | private String versionDescription; 16 | 17 | public PublishConfig(String functionAlias, String functionARN, String versionDescription){ 18 | this.functionAlias = functionAlias; 19 | this.functionARN = functionARN; 20 | this.versionDescription = versionDescription; 21 | } 22 | 23 | public void setFunctionAlias(String alias) { 24 | this.functionAlias = alias; 25 | } 26 | 27 | public String getFunctionAlias(){ 28 | return this.functionAlias; 29 | } 30 | 31 | public void setFunctionARN(String functionARN){ 32 | this.functionARN = functionARN; 33 | } 34 | 35 | public String getFunctionARN(){ 36 | return this.functionARN; 37 | } 38 | 39 | public String getVersionDescription() { 40 | return this.versionDescription; 41 | } 42 | 43 | public void setVersionDescription(String versionDescription){ 44 | this.versionDescription = versionDescription; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/webapp/help-synchronous.html: -------------------------------------------------------------------------------- 1 | 26 |
27 |

Synchronous/Asynchronous toggle

28 |

Synchronous allows Jenkins to collect the AWS Lambda function logs and response payload.

29 |
30 | -------------------------------------------------------------------------------- /src/main/webapp/help-handler.html: -------------------------------------------------------------------------------- 1 | 26 |
27 |

AWS Lambda handler name.

28 |

For nodejs: filename.handler

29 |

Warning: filename without .js and handler without export

30 |
31 | -------------------------------------------------------------------------------- /src/main/webapp/help-publishNewVersion.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | If checked the Lambda function will be created with a new version. 28 | If unchecked the Lambda function will deploy to the un-versioned function. 29 |
30 | -------------------------------------------------------------------------------- /src/main/webapp/help-deadletterqueue.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Target ARN of Amazon SQS queue or Amazon SNS topic. Add respectively sqs:SendMessage or sns:Publish as an allowed action on the target ARN in the role IAM policy. 28 |
29 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/AliasResult.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | public class AliasResult { 4 | private boolean success; 5 | private String functionName; 6 | private String functionVersion; 7 | private String functionAlias; 8 | 9 | public AliasResult(boolean success, String functionName, String functionVersion, String functionAlias) { 10 | this.success = success; 11 | this.functionName = functionName; 12 | this.functionVersion = functionVersion; 13 | this.functionAlias = functionAlias; 14 | } 15 | 16 | public boolean isSuccess() { 17 | return success; 18 | } 19 | 20 | public void setSuccess(boolean success) { 21 | this.success = success; 22 | } 23 | 24 | public String getFunctionName() { 25 | return functionName; 26 | } 27 | 28 | public void setFunctionName(String functionName) { 29 | this.functionName = functionName; 30 | } 31 | 32 | public String getFunctionVersion() { 33 | return functionVersion; 34 | } 35 | 36 | public void setFunctionVersion(String functionVersion) { 37 | this.functionVersion = functionVersion; 38 | } 39 | 40 | public String getFunctionAlias() { 41 | return functionAlias; 42 | } 43 | 44 | public void setFunctionAlias(String functionAlias) { 45 | this.functionAlias = functionAlias; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/webapp/help-successOnly.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | If checked the Lambda function will only be uploaded if the build was successful. 28 | If unchecked the Lambda function will also be uploaded for unstable builds. 29 |
30 | -------------------------------------------------------------------------------- /src/main/webapp/help-assignAlias.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | If checked the Lambda function will have the named alias assigned to the newly published function version. 28 | If unchecked the Lambda function will not be assigned an alias. 29 |
30 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishBuildStep/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
-------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishActionTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Created by Magnus Sulland on 4/08/2016. 9 | */ 10 | 11 | public class LambdaPublishActionTest { 12 | 13 | @Test 14 | public void testLambdaUploadActionSuccess(){ 15 | LambdaPublishAction lambdaUploadAction = new LambdaPublishAction("42", "alias1", true); 16 | 17 | assertEquals("Lambda alias alias1 points to version 42", lambdaUploadAction.getDisplayName()); 18 | assertEquals("console", lambdaUploadAction.getUrlName()); 19 | assertEquals("/plugin/aws-lambda/images/Lambda_24.png", lambdaUploadAction.getIconFileName()); 20 | assertEquals("/plugin/aws-lambda/images/Lambda_48.png", lambdaUploadAction.getBigIconFileName()); 21 | } 22 | 23 | @Test 24 | public void testLambdaUploadActionFailure(){ 25 | LambdaPublishAction lambdaUploadAction = new LambdaPublishAction("42", "alias1", false); 26 | 27 | assertEquals("Unable to point alias alias1 to version 42", lambdaUploadAction.getDisplayName()); 28 | assertEquals("console", lambdaUploadAction.getUrlName()); 29 | assertEquals("/plugin/aws-lambda/images/Lambda_24_grey.png", lambdaUploadAction.getIconFileName()); 30 | assertEquals("/plugin/aws-lambda/images/Lambda_48_grey.png", lambdaUploadAction.getBigIconFileName()); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/main/webapp/help-artifactLocation.html: -------------------------------------------------------------------------------- 1 | 26 |
27 |

Workspace zip or directory

28 |

29 | S3 location (Bucket must be in same region as Lambda function) 30 |
31 | s3://bucket/key or s3://bucket/key?versionId=versionId 32 |

33 |
34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### JetBrains template 2 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 3 | 4 | *.iml 5 | 6 | ## Directory-based project format: 7 | .idea/ 8 | # if you remove the above rule, at least ignore the following: 9 | 10 | # User-specific stuff: 11 | # .idea/workspace.xml 12 | # .idea/tasks.xml 13 | # .idea/dictionaries 14 | 15 | # Sensitive or high-churn files: 16 | # .idea/dataSources.ids 17 | # .idea/dataSources.xml 18 | # .idea/sqlDataSources.xml 19 | # .idea/dynamic.xml 20 | # .idea/uiDesigner.xml 21 | 22 | # Gradle: 23 | # .idea/gradle.xml 24 | # .idea/libraries 25 | 26 | # Mongo Explorer plugin: 27 | # .idea/mongoSettings.xml 28 | 29 | ## File-based project format: 30 | *.ipr 31 | *.iws 32 | 33 | ## Plugin-specific files: 34 | 35 | # IntelliJ 36 | /out/ 37 | 38 | # mpeltonen/sbt-idea plugin 39 | .idea_modules/ 40 | 41 | # JIRA plugin 42 | atlassian-ide-plugin.xml 43 | 44 | # Crashlytics plugin (for Android Studio and IntelliJ) 45 | com_crashlytics_export_strings.xml 46 | crashlytics.properties 47 | crashlytics-build.properties 48 | 49 | # Mobile Tools for Java (J2ME) 50 | .mtj.tmp/ 51 | 52 | # Package Files # 53 | *.jar 54 | *.war 55 | *.ear 56 | 57 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 58 | hs_err_pid* 59 | 60 | # Created by .ignore support plugin (hsz.mobi) 61 | 62 | # Jenkins work directory 63 | work/ 64 | 65 | # Maven target directory 66 | target 67 | 68 | # Maven Release Plugin 69 | release.properties -------------------------------------------------------------------------------- /src/main/webapp/help-subnets.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Subnets setting for AWS Lambda VPC configuration. Separate with commas and/or spaces. If supplied, fill in security groups from same VPC as well. 28 |
29 | Make sure the Lambda execution role has permissions to call ec2:CreateNetworkInterface. 30 |
31 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/service/JenkinsLoggerTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.PrintStream; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class JenkinsLoggerTest { 12 | private ByteArrayOutputStream logStream = new ByteArrayOutputStream(); 13 | private JenkinsLogger jenkinsLogger; 14 | private final String newLine = System.getProperty("line.separator"); 15 | 16 | @Before 17 | public void setUp() throws Exception { 18 | jenkinsLogger = new JenkinsLogger(new PrintStream(logStream)); 19 | } 20 | 21 | @Test 22 | public void testLog() throws Exception { 23 | jenkinsLogger.log("test"); 24 | assertEquals("test" + newLine, logStream.toString()); 25 | } 26 | 27 | @Test 28 | public void testLogMultiLine() throws Exception { 29 | jenkinsLogger.log("test"); 30 | jenkinsLogger.log("also"); 31 | assertEquals("test" + newLine + "also" + newLine, logStream.toString()); 32 | } 33 | 34 | @Test 35 | public void testLogMask() throws Exception { 36 | jenkinsLogger.log("test: %s", "something"); 37 | assertEquals("test: something" + newLine, logStream.toString()); 38 | } 39 | 40 | @Test 41 | public void testLogMaskNull() throws Exception { 42 | jenkinsLogger.log(null); 43 | assertEquals("", logStream.toString()); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/webapp/help-securityGroups.html: -------------------------------------------------------------------------------- 1 | 26 |
27 | Security groups setting for AWS Lambda VPC configuration. Separate with commas and/or spaces. If supplied, fill in subnets from same VPC as well. 28 |
29 | Make sure the Lambda execution role has permissions to call ec2:CreateNetworkInterface. 30 |
31 | -------------------------------------------------------------------------------- /src/main/webapp/help-awsRegion.html: -------------------------------------------------------------------------------- 1 | 26 | 30 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/util/TokenizerTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * Project: aws-lambda 12 | * Created by Michael Willemse on 12/02/2016. 13 | */ 14 | public class TokenizerTest { 15 | 16 | @Test 17 | public void testValidExpectedString(){ 18 | String input = "subnet1, subnet2, subnet3"; 19 | List fixture = Arrays.asList("subnet1", "subnet2", "subnet3"); 20 | 21 | assertEquals(fixture, Tokenizer.split(input)); 22 | } 23 | 24 | @Test 25 | public void testValidMuchWhitespace(){ 26 | String input = "subnet1, , subnet2, subnet3, "; 27 | List fixture = Arrays.asList("subnet1", "subnet2", "subnet3"); 28 | 29 | assertEquals(fixture, Tokenizer.split(input)); 30 | } 31 | 32 | @Test 33 | public void testValidStartEndWhitespace(){ 34 | String input = " subnet1, subnet2, subnet3 "; 35 | List fixture = Arrays.asList("subnet1", "subnet2", "subnet3"); 36 | 37 | assertEquals(fixture, Tokenizer.split(input)); 38 | } 39 | 40 | @Test 41 | public void testValidEmpty(){ 42 | String input = ""; 43 | 44 | assertEquals(0, Tokenizer.split(input).size()); 45 | } 46 | 47 | @Test 48 | public void testValidNull(){ 49 | assertEquals(0, Tokenizer.split(null).size()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/InvokeConfig.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class InvokeConfig implements Serializable { 7 | private String functionName; 8 | private String payload; 9 | private boolean synchronous; 10 | private List jsonParameters; 11 | 12 | public InvokeConfig(String functionName, String payload, boolean synchronous, List jsonParameters) { 13 | this.functionName = functionName; 14 | this.payload = payload; 15 | this.synchronous = synchronous; 16 | this.jsonParameters = jsonParameters; 17 | } 18 | 19 | public String getFunctionName() { 20 | return functionName; 21 | } 22 | 23 | public void setFunctionName(String functionName) { 24 | this.functionName = functionName; 25 | } 26 | 27 | public String getPayload() { 28 | return payload; 29 | } 30 | 31 | public void setPayload(String payload) { 32 | this.payload = payload; 33 | } 34 | 35 | public boolean isSynchronous() { 36 | return synchronous; 37 | } 38 | 39 | public void setSynchronous(boolean synchronous) { 40 | this.synchronous = synchronous; 41 | } 42 | 43 | public List getJsonParameters() { 44 | return jsonParameters; 45 | } 46 | 47 | public void setJsonParameters(List jsonParameters) { 48 | this.jsonParameters = jsonParameters; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourceAction.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.eventsource; 2 | 3 | import hudson.model.ProminentProjectAction; 4 | 5 | /** 6 | * Created by anthonyikeda on 25/11/2015. 7 | */ 8 | public class LambdaEventSourceAction implements ProminentProjectAction { 9 | private static final String URL_NAME = "console"; 10 | 11 | private final String iconFileName; 12 | private final String bigIconFileName; 13 | private final String displayName; 14 | 15 | public LambdaEventSourceAction(String functionName, Boolean success) { 16 | if(success){ 17 | iconFileName = "/plugin/aws-lambda/images/Lambda_24.png"; 18 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48.png"; 19 | displayName = "Lambda event sources created: " + functionName; 20 | }else { 21 | iconFileName = "/plugin/aws-lambda/images/Lambda_24_grey.png"; 22 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48_grey.png"; 23 | displayName = "Lambda event sources creation failure: " + functionName; 24 | } 25 | } 26 | 27 | @Override 28 | public String getIconFileName() { 29 | return iconFileName; 30 | } 31 | 32 | public String getBigIconFileName() { 33 | return bigIconFileName; 34 | } 35 | 36 | @Override 37 | public String getDisplayName() { 38 | return displayName; 39 | } 40 | 41 | @Override 42 | public String getUrlName() { 43 | return URL_NAME; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourceBuildStep/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
-------------------------------------------------------------------------------- /src/main/webapp/help-jsonPath.html: -------------------------------------------------------------------------------- 1 | 26 |
27 |

JsonPath expression used to parse AWS Lambda response payload. Leave empty to get full payload.

28 |

https://github.com/jayway/JsonPath

29 |

Example: $.output.key1 for {"output" : {"key1":"value1"}} returns value1

30 |
31 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeBuildStep/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishAction.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import hudson.model.ProminentProjectAction; 4 | 5 | /** 6 | * Project: aws-lambda 7 | * Created by Magnus Sulland on 26/07/2016. 8 | */ 9 | public class LambdaPublishAction implements ProminentProjectAction{ 10 | private static final String URL_NAME = "console"; 11 | 12 | private final String iconFileName; 13 | private final String bigIconFileName; 14 | private final String displayName; 15 | 16 | public LambdaPublishAction(String functionVersion, String functionAlias, Boolean success) { 17 | if(success){ 18 | iconFileName = "/plugin/aws-lambda/images/Lambda_24.png"; 19 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48.png"; 20 | displayName = "Lambda alias " + functionAlias + " points to version " + functionVersion; 21 | }else { 22 | iconFileName = "/plugin/aws-lambda/images/Lambda_24_grey.png"; 23 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48_grey.png"; 24 | displayName = "Unable to point alias " + functionAlias + " to version " + functionVersion; 25 | } 26 | } 27 | 28 | @Override 29 | public String getIconFileName() { 30 | return iconFileName; 31 | } 32 | 33 | public String getBigIconFileName() { 34 | return bigIconFileName; 35 | } 36 | 37 | @Override 38 | public String getDisplayName() { 39 | return displayName; 40 | } 41 | 42 | @Override 43 | public String getUrlName() { 44 | return URL_NAME; 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/EventSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.eventsource; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by anthonyikeda on 25/11/2015. 7 | * 8 | */ 9 | public class EventSourceConfig implements Serializable { 10 | 11 | private String functionName; 12 | private String functionAlias; 13 | private String eventSourceArn; 14 | private String startingPosition; 15 | 16 | public EventSourceConfig(String functionName, String functionAlias, String eventSourceArn) { 17 | this.functionName = functionName; 18 | this.functionAlias = functionAlias; 19 | this.eventSourceArn = eventSourceArn; 20 | this.startingPosition = "LATEST"; 21 | } 22 | 23 | public String getEventSourceArn() { 24 | return eventSourceArn; 25 | } 26 | 27 | public void setEventSourceArn(String eventSourceArn) { 28 | this.eventSourceArn = eventSourceArn; 29 | } 30 | 31 | public String getFunctionAlias() { 32 | return functionAlias; 33 | } 34 | 35 | public void setFunctionAlias(String alias) { 36 | this.functionAlias = alias; 37 | } 38 | 39 | public String getFunctionName() { 40 | return functionName; 41 | } 42 | 43 | public void setFunctionName(String functionName) { 44 | this.functionName = functionName; 45 | } 46 | 47 | public String getStartingPosition() { 48 | return startingPosition; 49 | } 50 | 51 | public void setStartingPosition(String startingPosition) { 52 | this.startingPosition = startingPosition; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/webapp/images/Lambda.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/callable/EventSourceCallable.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.callable; 2 | 3 | import com.xti.jenkins.plugin.awslambda.eventsource.EventSourceBuilder; 4 | import com.xti.jenkins.plugin.awslambda.eventsource.EventSourceConfig; 5 | import com.xti.jenkins.plugin.awslambda.invoke.InvokeConfig; 6 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 7 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 8 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 9 | import hudson.model.BuildListener; 10 | import hudson.model.TaskListener; 11 | import hudson.remoting.Callable; 12 | import org.jenkinsci.remoting.RoleChecker; 13 | 14 | /** 15 | * Project: aws-lambda 16 | * Created by Michael on 16/01/2016. 17 | */ 18 | public class EventSourceCallable implements Callable { 19 | 20 | private TaskListener listener; 21 | private EventSourceConfig eventSourceConfig; 22 | private LambdaClientConfig clientConfig; 23 | 24 | public EventSourceCallable(TaskListener listener, EventSourceConfig eventSourceConfig, LambdaClientConfig clientConfig) { 25 | this.listener = listener; 26 | this.eventSourceConfig = eventSourceConfig; 27 | this.clientConfig = clientConfig; 28 | } 29 | 30 | @Override 31 | public Boolean call() throws RuntimeException { 32 | JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); 33 | LambdaDeployService service = new LambdaDeployService(clientConfig.getClient(), logger); 34 | EventSourceBuilder builder = new EventSourceBuilder(service, logger); 35 | 36 | return builder.createEventSource(eventSourceConfig); 37 | } 38 | 39 | @Override 40 | public void checkRoles(RoleChecker roleChecker) throws SecurityException { 41 | //ignore for now 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/AliasConfig.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AliasConfig implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | public AliasConfig(boolean createAlias, String aliasName, String aliasDescription, String functionName, String functionVersion) { 10 | this.createAlias = createAlias; 11 | this.aliasName = aliasName; 12 | this.aliasDescription = aliasDescription; 13 | this.functionName = functionName; 14 | this.functionVersion = functionVersion; 15 | } 16 | 17 | private boolean createAlias; 18 | private String aliasName; 19 | private String aliasDescription; 20 | private String functionName; 21 | private String functionVersion; 22 | 23 | public boolean isCreateAlias() { 24 | return createAlias; 25 | } 26 | 27 | public void setCreateAlias(boolean createAlias) { 28 | this.createAlias = createAlias; 29 | } 30 | 31 | public String getAliasName() { 32 | return aliasName; 33 | } 34 | 35 | public void setAliasName(String aliasName) { 36 | this.aliasName = aliasName; 37 | } 38 | 39 | public String getAliasDescription() { 40 | return aliasDescription; 41 | } 42 | 43 | public void setAliasDescription(String aliasDescription) { 44 | this.aliasDescription = aliasDescription; 45 | } 46 | 47 | public String getFunctionName() { 48 | return functionName; 49 | } 50 | 51 | public void setFunctionName(String functionName) { 52 | this.functionName = functionName; 53 | } 54 | 55 | public String getFunctionVersion() { 56 | return functionVersion; 57 | } 58 | 59 | public void setFunctionVersion(String functionVersion) { 60 | this.functionVersion = functionVersion; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/JsonPathParser.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import com.jayway.jsonpath.DocumentContext; 4 | import com.jayway.jsonpath.JsonPath; 5 | import com.jayway.jsonpath.JsonPathException; 6 | import com.xti.jenkins.plugin.awslambda.invoke.JsonParameter; 7 | import com.xti.jenkins.plugin.awslambda.util.LogUtils; 8 | import org.apache.commons.lang.StringUtils; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class JsonPathParser { 15 | private List jsonParameters; 16 | private JenkinsLogger logger; 17 | 18 | 19 | public JsonPathParser(List jsonParameters, JenkinsLogger logger) { 20 | this.jsonParameters = jsonParameters; 21 | this.logger = logger; 22 | } 23 | 24 | public Map parse(String payload){ 25 | Map result = new HashMap(); 26 | if(StringUtils.isNotEmpty(payload)) { 27 | DocumentContext documentContext = JsonPath.parse(payload); 28 | 29 | for (JsonParameter jsonParameter : jsonParameters) { 30 | if (StringUtils.isEmpty(jsonParameter.getJsonPath())) { 31 | result.put(jsonParameter.getEnvVarName(), payload); 32 | } else { 33 | try { 34 | result.put(jsonParameter.getEnvVarName(), documentContext.read(jsonParameter.getJsonPath()).toString()); 35 | } catch (JsonPathException jpe) { 36 | logger.log("Error while parsing path %s for environment variable %s.%nStacktrace:%n%s%n", 37 | jsonParameter.getJsonPath(), jsonParameter.getEnvVarName(), LogUtils.getStackTrace(jpe)); 38 | } 39 | } 40 | } 41 | } 42 | 43 | return result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourceBuildStepVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/callable/PublishCallable.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.callable; 2 | 3 | import com.xti.jenkins.plugin.awslambda.publish.LambdaPublishServiceResponse; 4 | import com.xti.jenkins.plugin.awslambda.publish.LambdaPublisher; 5 | import com.xti.jenkins.plugin.awslambda.publish.PublishConfig; 6 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 7 | import com.xti.jenkins.plugin.awslambda.service.LambdaPublishService; 8 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 9 | import hudson.model.TaskListener; 10 | import hudson.remoting.Callable; 11 | import org.jenkinsci.remoting.RoleChecker; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * Project: aws-lambda 17 | * Created by Magnus Sulland on 26/07/2016. 18 | */ 19 | public class PublishCallable implements Callable { 20 | 21 | private TaskListener listener; 22 | private PublishConfig publishConfig; 23 | private LambdaClientConfig clientConfig; 24 | 25 | public PublishCallable(TaskListener listener, PublishConfig publishConfig, LambdaClientConfig lambdaClientConfig) { 26 | this.listener = listener; 27 | this.publishConfig = publishConfig; 28 | this.clientConfig = lambdaClientConfig; 29 | } 30 | 31 | @Override 32 | public LambdaPublishServiceResponse call() throws RuntimeException { 33 | 34 | JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); 35 | LambdaPublishService service = new LambdaPublishService(clientConfig.getClient(), logger); 36 | 37 | try { 38 | LambdaPublisher publishPublisher = new LambdaPublisher(service, logger); 39 | return publishPublisher.publish(publishConfig); 40 | } catch (IOException | InterruptedException e) { 41 | throw new RuntimeException(e); 42 | } 43 | } 44 | 45 | @Override 46 | public void checkRoles(RoleChecker roleChecker) throws SecurityException { 47 | //ignore for now 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishPublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 |
28 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/JsonParameter.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | 30 | import java.io.Serializable; 31 | 32 | public class JsonParameter implements Serializable { 33 | private String envVarName; 34 | private String jsonPath; 35 | 36 | public JsonParameter(String envVarName, String jsonPath) { 37 | this.envVarName = envVarName; 38 | this.jsonPath = jsonPath; 39 | } 40 | 41 | public String getEnvVarName() { 42 | return envVarName; 43 | } 44 | 45 | public String getJsonPath() { 46 | return jsonPath; 47 | } 48 | 49 | public void setEnvVarName(String envVarName) { 50 | this.envVarName = envVarName; 51 | } 52 | 53 | public void setJsonPath(String jsonPath) { 54 | this.jsonPath = jsonPath; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/webapp/js/awslambda.js: -------------------------------------------------------------------------------- 1 | function updateAwsLambdaOptionalBlock(c,scroll) { 2 | // find the start TR 3 | var s = $(c); 4 | while(!s.hasClassName("awslambda-optional-block-start")) 5 | s = s.up(); 6 | 7 | // find the beginning of the rowvg 8 | var vg =s; 9 | while (!vg.hasClassName("rowvg-start")) 10 | vg = vg.next(); 11 | 12 | var checked = xor(c.checked,Element.hasClassName(c.parentElement.parentElement,"negative")); 13 | 14 | vg.rowVisibilityGroup.makeInnerVisisble(checked); 15 | 16 | if (checked && scroll) { 17 | var D = YAHOO.util.Dom; 18 | 19 | var r = D.getRegion(s); 20 | r = r.union(D.getRegion(vg.rowVisibilityGroup.end)); 21 | scrollIntoView(r); 22 | } 23 | 24 | if (c.name == 'hudson-tools-InstallSourceProperty') { 25 | // Hack to hide tool home when "Install automatically" is checked. 26 | var homeField = findPreviousFormItem(c, 'home'); 27 | if (homeField != null && homeField.value == '') { 28 | var tr = findAncestor(homeField, 'TR'); 29 | if (tr != null) { 30 | tr.style.display = c.checked ? 'none' : ''; 31 | layoutUpdateCallback.call(); 32 | } 33 | } 34 | } 35 | } 36 | 37 | document.addEventListener("DOMContentLoaded", function() { 38 | Behaviour.specify("TR.awslambda-optional-block-start", "awslambda-optional-block-start", 100, function(e) { 39 | // set start.ref to checkbox in preparation of row-set-end processing 40 | var checkbox = e.down().down(); 41 | e.setAttribute("ref", checkbox.id = "cb"+(iota++)); 42 | }); 43 | 44 | Behaviour.specify("TR.awslambda-optional-block-start ", "awslambda-optional-block-start ", 100, function(e) { // see optionalBlock.jelly 45 | // this is suffixed by a pointless string so that two processing for optional-block-start 46 | // can sandwitch row-set-end 47 | // this requires "TR.row-set-end" to mark rows 48 | var checkbox = e.down().down(); 49 | updateAwsLambdaOptionalBlock(checkbox,false); 50 | }); 51 | }); -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/WorkSpaceZipper.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import com.xti.jenkins.plugin.awslambda.exception.LambdaDeployException; 4 | import hudson.FilePath; 5 | import hudson.util.DirScanner; 6 | import org.apache.commons.lang.StringUtils; 7 | 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | 12 | public class WorkSpaceZipper { 13 | private FilePath workSpace; 14 | private JenkinsLogger logger; 15 | 16 | public WorkSpaceZipper(FilePath workSpace, JenkinsLogger logger) { 17 | this.workSpace = workSpace; 18 | this.logger = logger; 19 | } 20 | 21 | public File getZip(String artifactLocation) throws IOException, InterruptedException { 22 | FilePath artifactFilePath = null; 23 | 24 | if(StringUtils.isNotEmpty(artifactLocation)) { 25 | artifactFilePath = new FilePath(workSpace, artifactLocation); 26 | } 27 | File zipFile = null; 28 | if(artifactFilePath != null){ 29 | zipFile = getArtifactZip(artifactFilePath); 30 | } 31 | 32 | return zipFile; 33 | } 34 | 35 | private File getArtifactZip(FilePath artifactLocation) throws IOException, InterruptedException { 36 | File resultFile = File.createTempFile("awslambda-", ".zip"); 37 | 38 | if (!artifactLocation.isDirectory()) { 39 | if(artifactLocation.exists()) { 40 | logger.log("Copying zip file"); 41 | artifactLocation.copyTo(new FileOutputStream(resultFile)); 42 | } else { 43 | throw new LambdaDeployException("Could not find zipfile or folder."); 44 | } 45 | } else { 46 | logger.log("Zipping folder ..., copying zip file"); 47 | artifactLocation.zip(new FileOutputStream(resultFile), new DirScanner.Glob("**", null, false)); 48 | } 49 | 50 | logger.log("File Name: %s%nAbsolute Path: %s%nFile Size: %d", resultFile.getName(), resultFile.getAbsolutePath(), resultFile.length()); 51 | return resultFile; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishBuildStepVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 |
30 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/callable/DeployCallable.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.callable; 2 | 3 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 4 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 5 | import com.xti.jenkins.plugin.awslambda.service.WorkSpaceZipper; 6 | import com.xti.jenkins.plugin.awslambda.upload.DeployConfig; 7 | import com.xti.jenkins.plugin.awslambda.upload.LambdaUploader; 8 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 9 | import hudson.FilePath; 10 | import hudson.model.TaskListener; 11 | import hudson.remoting.Callable; 12 | import org.jenkinsci.remoting.RoleChecker; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * Project: aws-lambda 18 | * Created by Michael on 16/01/2016. 19 | */ 20 | public class DeployCallable implements Callable { 21 | 22 | private TaskListener listener; 23 | private FilePath localWorkSpacePath; 24 | private DeployConfig deployConfig; 25 | private LambdaClientConfig clientConfig; 26 | 27 | public DeployCallable(TaskListener listener, FilePath localWorkSpacePath, DeployConfig deployConfig, LambdaClientConfig lambdaClientConfig) { 28 | this.listener = listener; 29 | this.localWorkSpacePath = localWorkSpacePath; 30 | this.deployConfig = deployConfig; 31 | this.clientConfig = lambdaClientConfig; 32 | } 33 | 34 | @Override 35 | public Boolean call() throws RuntimeException { 36 | 37 | JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); 38 | LambdaDeployService service = new LambdaDeployService(clientConfig.getClient(), logger); 39 | WorkSpaceZipper workSpaceZipper = new WorkSpaceZipper(localWorkSpacePath, logger); 40 | 41 | try { 42 | LambdaUploader lambdaUploader = new LambdaUploader(service, workSpaceZipper, logger); 43 | return lambdaUploader.upload(deployConfig); 44 | } catch (IOException | InterruptedException e) { 45 | throw new RuntimeException(e); 46 | } 47 | } 48 | 49 | @Override 50 | public void checkRoles(RoleChecker roleChecker) throws SecurityException { 51 | //ignore for now 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/callable/InvokeCallable.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.callable; 2 | 3 | import com.xti.jenkins.plugin.awslambda.invoke.InvokeConfig; 4 | import com.xti.jenkins.plugin.awslambda.invoke.LambdaInvocationResult; 5 | import com.xti.jenkins.plugin.awslambda.invoke.LambdaInvoker; 6 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 7 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 8 | import com.xti.jenkins.plugin.awslambda.service.LambdaInvokeService; 9 | import com.xti.jenkins.plugin.awslambda.service.WorkSpaceZipper; 10 | import com.xti.jenkins.plugin.awslambda.upload.DeployConfig; 11 | import com.xti.jenkins.plugin.awslambda.upload.LambdaUploader; 12 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 13 | import hudson.FilePath; 14 | import hudson.model.BuildListener; 15 | import hudson.model.TaskListener; 16 | import hudson.remoting.Callable; 17 | import org.jenkinsci.remoting.RoleChecker; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * Project: aws-lambda 23 | * Created by Michael on 16/01/2016. 24 | */ 25 | public class InvokeCallable implements Callable { 26 | 27 | private TaskListener listener; 28 | private InvokeConfig invokeConfig; 29 | private LambdaClientConfig clientConfig; 30 | 31 | public InvokeCallable(TaskListener listener, InvokeConfig invokeConfig, LambdaClientConfig lambdaClientConfig) { 32 | this.listener = listener; 33 | this.invokeConfig = invokeConfig; 34 | this.clientConfig = lambdaClientConfig; 35 | } 36 | 37 | @Override 38 | public LambdaInvocationResult call() throws RuntimeException { 39 | 40 | JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); 41 | LambdaInvokeService service = new LambdaInvokeService(clientConfig.getClient(), logger); 42 | LambdaInvoker lambdaInvoker = new LambdaInvoker(service, logger); 43 | 44 | try { 45 | return lambdaInvoker.invoke(invokeConfig); 46 | } catch (IOException | InterruptedException e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | @Override 52 | public void checkRoles(RoleChecker roleChecker) throws SecurityException { 53 | //ignore for now 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeBuildStepVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 |
33 |
-------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokerTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import com.xti.jenkins.plugin.awslambda.exception.LambdaInvokeException; 4 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 5 | import com.xti.jenkins.plugin.awslambda.service.LambdaInvokeService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.mockito.Mock; 9 | import org.mockito.runners.MockitoJUnitRunner; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertFalse; 16 | import static org.junit.Assert.assertTrue; 17 | import static org.mockito.Matchers.any; 18 | import static org.mockito.Mockito.*; 19 | 20 | @RunWith(MockitoJUnitRunner.class) 21 | public class LambdaInvokerTest { 22 | 23 | @Mock 24 | private LambdaInvokeService service; 25 | 26 | @Mock 27 | private JenkinsLogger logger; 28 | 29 | @Test 30 | public void testInvokeSuccess() throws Exception { 31 | when(service.invokeLambdaFunction(any(InvokeConfig.class))).thenReturn("{\"key2\":\"value2\"}"); 32 | 33 | LambdaInvoker invoker = new LambdaInvoker(service, logger); 34 | 35 | InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key\":\"value\"}", true, Collections.singletonList(new JsonParameter("LAMBDA_ENV_VAR", "$.key2"))); 36 | 37 | LambdaInvocationResult result = invoker.invoke(invokeConfig); 38 | 39 | assertTrue(result.isSuccess()); 40 | assertEquals("value2", result.getInjectables().get("LAMBDA_ENV_VAR")); 41 | } 42 | 43 | @Test 44 | public void testInvokeFailure() throws Exception { 45 | when(service.invokeLambdaFunction(any(InvokeConfig.class))).thenThrow(new LambdaInvokeException("Function returned error of type: Handled")); 46 | 47 | LambdaInvoker invoker = new LambdaInvoker(service, logger); 48 | 49 | InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key\":\"value\"}", true, new ArrayList()); 50 | 51 | LambdaInvocationResult result = invoker.invoke(invokeConfig); 52 | 53 | assertFalse(result.isSuccess()); 54 | assertEquals(0, result.getInjectables().size()); 55 | 56 | verify(logger, times(1)).log("%nStarting lambda invocation."); 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/AWSLambdaDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda; 2 | 3 | import hudson.model.Describable; 4 | import hudson.model.Descriptor; 5 | import hudson.util.FormValidation; 6 | import org.apache.commons.lang.StringUtils; 7 | import org.kohsuke.stapler.QueryParameter; 8 | 9 | public abstract class AWSLambdaDescriptor> extends Descriptor { 10 | 11 | //awsAccessKeyId field 12 | public FormValidation doCheckAwsAccessKeyId(@QueryParameter String value) { 13 | if(StringUtils.isEmpty(value)){ 14 | return FormValidation.error("Please fill in AWS Access Key Id."); 15 | } else { 16 | return FormValidation.ok(); 17 | } 18 | } 19 | 20 | //awsSecretKey field 21 | public FormValidation doCheckAwsSecretKey(@QueryParameter String value) { 22 | if(StringUtils.isEmpty(value)){ 23 | return FormValidation.error("Please fill in AWS Secret Id."); 24 | } else { 25 | return FormValidation.ok(); 26 | } 27 | } 28 | 29 | //awsRegion field 30 | public FormValidation doCheckAwsRegion(@QueryParameter String value) { 31 | if(StringUtils.isEmpty(value)){ 32 | return FormValidation.error("Please fill in AWS Region."); 33 | } else { 34 | return FormValidation.ok(); 35 | } 36 | } 37 | 38 | //functionName field 39 | public FormValidation doCheckFunctionName(@QueryParameter String value) { 40 | if(StringUtils.isEmpty(value)){ 41 | return FormValidation.error("Please fill in AWS Lambda function name."); 42 | } else { 43 | return FormValidation.ok(); 44 | } 45 | } 46 | 47 | //functionARN field 48 | public FormValidation doCheckFunctionARN(@QueryParameter String value) { 49 | if(StringUtils.isEmpty(value)){ 50 | return FormValidation.error("Please fill in AWS Lambda function ARN."); 51 | } else { 52 | return FormValidation.ok(); 53 | } 54 | } 55 | 56 | //functionAlias field 57 | public FormValidation doCheckFunctionAlias(@QueryParameter String value) { 58 | if(StringUtils.isEmpty(value)){ 59 | return FormValidation.error("Please fill in AWS Lambda alias name."); 60 | } else { 61 | return FormValidation.ok(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploader.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.amazonaws.services.lambda.model.FunctionCode; 30 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 31 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 32 | import com.xti.jenkins.plugin.awslambda.service.WorkSpaceZipper; 33 | 34 | import java.io.IOException; 35 | 36 | public class LambdaUploader { 37 | private LambdaDeployService lambda; 38 | private WorkSpaceZipper zipper; 39 | private JenkinsLogger logger; 40 | 41 | public LambdaUploader(LambdaDeployService lambda, WorkSpaceZipper zipper, JenkinsLogger logger) throws IOException, InterruptedException { 42 | this.lambda = lambda; 43 | this.zipper = zipper; 44 | this.logger = logger; 45 | } 46 | 47 | public Boolean upload(DeployConfig config) throws IOException, InterruptedException { 48 | logger.log("%nStarting lambda deployment procedure"); 49 | 50 | FunctionCode functionCode = lambda.getFunctionCode(config.getArtifactLocation(), zipper); 51 | return lambda.deployLambda(config, functionCode, UpdateModeValue.fromString(config.getUpdateMode())); 52 | } 53 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.10 (2017-03-19) 2 | 3 | Bugfixes: 4 | 5 | - Instance Credentials are now saved and used when using the publish new version post build action. [Issue 68](https://github.com/XT-i/aws-lambda-jenkins-plugin/issues/68) 6 | 7 | ## 0.5.9 (2017-03-04) 8 | 9 | Bugfixes: 10 | 11 | - PublishConfig and AliasConfig now implement Serializable [Issue 64](https://github.com/XT-i/aws-lambda-jenkins-plugin/issues/64) 12 | 13 | Features: 14 | 15 | - Added the following short forms for build step pipeline usage: deployLambda, invokeLambda, publishLambda and eventSourceLambda 16 | 17 | ## 0.5.8 (2017-01-11) 18 | 19 | Bugfixes: 20 | 21 | - Adding empty lists in VPCConfig when not set to circumvent AWS backend change. 22 | 23 | ## 0.5.7 (2017-01-02) 24 | 25 | Features: 26 | 27 | - Added support for dead letter queue configuration 28 | 29 | ## 0.5.6 (2016-11-20) 30 | 31 | Features: 32 | 33 | - Added support for AWS Lambda environment variables 34 | 35 | ## 0.5.5 (2016-08-26) 36 | 37 | Features: 38 | 39 | - Added support for Jenkins managed proxy configuration 40 | 41 | ## 0.5.4 (2016-08-09) 42 | 43 | Features: 44 | 45 | - Added a separate deploy version and update Lambda alias build step 46 | 47 | ## 0.5.3 (2016-04-09) 48 | 49 | Bugfixes: 50 | 51 | - Fixed problem where zip functionality would continue until full disk if folder was root of workspace. [Issue 41](https://github.com/XT-i/aws-lambda-jenkins-plugin/issues/41) 52 | 53 | ## 0.5.2 (2016-04-09) 54 | 55 | Features: 56 | 57 | - Allow changing runtime environment. 58 | 59 | ## 0.5.1 (2016-03-14) 60 | 61 | Bugfixes: 62 | 63 | - Fixed non serializable JsonParameter to allow distributed build with Lambda invocation output directed into environment variables 64 | 65 | ## 0.5.0 (2016-02-13) 66 | 67 | Features: 68 | 69 | - Jenkins Pipeline support (General Build Step) 70 | 71 | ## 0.4.3 (2016-02-26) 72 | 73 | Bugfixes: 74 | 75 | - Empty timeout and memory no longer throws a NumberFormatException as they are not required when updating code only. 76 | 77 | ## 0.4.2 (2016-02-26) 78 | 79 | Bugfixes: 80 | 81 | - Now using workspace to store temporary artifact file instead of system temporary folder. 82 | 83 | ## 0.4.1 (2016-02-13) 84 | 85 | Features: 86 | 87 | - AWS Lambda VPC support 88 | - Advanced block to reduce screen space used. Preparation for move to @DataboundSetter 89 | 90 | Bugfixes: 91 | 92 | - Job success only toggle fixed for event source configuration 93 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourcePublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 |
36 |
37 |
-------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 4 | import com.xti.jenkins.plugin.awslambda.service.LambdaPublishService; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.mockito.Mock; 8 | import org.mockito.runners.MockitoJUnitRunner; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertTrue; 12 | import static org.junit.Assert.assertFalse; 13 | import static org.mockito.Matchers.any; 14 | import static org.mockito.Mockito.times; 15 | import static org.mockito.Mockito.verify; 16 | import static org.mockito.Mockito.when; 17 | 18 | /** 19 | * Created by Magnus Sulland on 4/08/2016. 20 | */ 21 | 22 | @RunWith(MockitoJUnitRunner.class) 23 | public class LambdaPublishTest { 24 | 25 | @Mock 26 | private LambdaPublishService service; 27 | 28 | @Mock 29 | private JenkinsLogger logger; 30 | 31 | @Test 32 | public void testPublishSuccess() throws Exception { 33 | when(service.publishLambda(any(PublishConfig.class))).thenReturn(new LambdaPublishServiceResponse("VERSION", "ALIAS", true)); 34 | 35 | LambdaPublisher publisher = new LambdaPublisher(service, logger); 36 | 37 | PublishConfig publishConfig = new PublishConfig("ALIAS", "ARN", "DESCRIPTION"); 38 | 39 | LambdaPublishServiceResponse result = publisher.publish(publishConfig); 40 | 41 | verify(logger, times(1)).log("%nStarting lambda publish procedure"); 42 | 43 | assertEquals(publishConfig.getFunctionAlias(), result.getFunctionAlias()); 44 | assertEquals(result.getFunctionVersion(), "VERSION"); 45 | 46 | assertTrue(result.getSuccess()); 47 | } 48 | 49 | @Test 50 | public void testPublishFailure() throws Exception { 51 | when(service.publishLambda(any(PublishConfig.class))).thenReturn(new LambdaPublishServiceResponse("VERSION", "ALIAS", false)); 52 | 53 | LambdaPublisher publisher = new LambdaPublisher(service, logger); 54 | 55 | PublishConfig publishConfig = new PublishConfig("ALIAS", "ARN", "DESCRIPTION"); 56 | 57 | LambdaPublishServiceResponse result = publisher.publish(publishConfig); 58 | 59 | verify(logger, times(1)).log("%nStarting lambda publish procedure"); 60 | 61 | assertEquals(publishConfig.getFunctionAlias(), result.getFunctionAlias()); 62 | assertEquals(result.getFunctionVersion(), "VERSION"); 63 | 64 | assertFalse(result.getSuccess()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/LambdaPublishService.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import com.amazonaws.services.lambda.AWSLambdaClient; 4 | import com.amazonaws.services.lambda.model.*; 5 | import com.xti.jenkins.plugin.awslambda.publish.LambdaPublishServiceResponse; 6 | import com.xti.jenkins.plugin.awslambda.publish.PublishConfig; 7 | 8 | /** 9 | * Project: aws-lambda 10 | * Created by Magnus Sulland on 26/07/2016. 11 | */ 12 | public class LambdaPublishService { 13 | private AWSLambdaClient client; 14 | private JenkinsLogger logger; 15 | 16 | public LambdaPublishService(AWSLambdaClient client, JenkinsLogger logger) { 17 | this.client = client; 18 | this.logger = logger; 19 | } 20 | 21 | public LambdaPublishServiceResponse publishLambda(PublishConfig config){ 22 | 23 | GetAliasRequest getAliasRequest = new GetAliasRequest() 24 | .withName(config.getFunctionAlias()) 25 | .withFunctionName(config.getFunctionARN()); 26 | 27 | logger.log("Lambda function alias existence check:%n%s%n%s%n", config.getFunctionARN(), config.getFunctionAlias()); 28 | try { 29 | GetAliasResult functionResult = client.getAlias(getAliasRequest); 30 | logger.log("Lambda function alias exists:%n%s%n", functionResult.toString()); 31 | } catch (ResourceNotFoundException rnfe) { 32 | return new LambdaPublishServiceResponse("", "", false); 33 | } 34 | 35 | logger.log("Publishing new version"); 36 | 37 | PublishVersionRequest publishVersionRequest = new PublishVersionRequest().withFunctionName(config.getFunctionARN()).withDescription(config.getVersionDescription()); 38 | PublishVersionResult publishVersionResult = client.publishVersion(publishVersionRequest); 39 | 40 | logger.log(publishVersionResult.toString()); 41 | 42 | logger.log("Updating alias"); 43 | 44 | UpdateAliasRequest updateAliasRequest = new UpdateAliasRequest().withName(config.getFunctionAlias()); 45 | updateAliasRequest.setFunctionName(config.getFunctionARN()); 46 | updateAliasRequest.setDescription(config.getVersionDescription()); 47 | updateAliasRequest.setFunctionVersion(publishVersionResult.getVersion()); 48 | 49 | UpdateAliasResult updateAliasResult = client.updateAlias(updateAliasRequest); 50 | 51 | logger.log(updateAliasResult.toString()); 52 | 53 | return new LambdaPublishServiceResponse(publishVersionResult.getVersion(), updateAliasResult.getName(), true); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokePublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | 35 |
36 |
37 |
38 |
39 |
40 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeAction.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import hudson.model.ProminentProjectAction; 30 | 31 | public class LambdaInvokeAction implements ProminentProjectAction { 32 | 33 | //Nothing to show, go to console for now 34 | private static final String URL_NAME = "console"; 35 | 36 | private final String iconFileName; 37 | private final String bigIconFileName; 38 | private final String displayName; 39 | 40 | 41 | public LambdaInvokeAction(String functionName, Boolean success) { 42 | if(success){ 43 | iconFileName = "/plugin/aws-lambda/images/Lambda_24.png"; 44 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48.png"; 45 | displayName = "Invoked Lambda: " + functionName; 46 | }else { 47 | iconFileName = "/plugin/aws-lambda/images/Lambda_24_grey.png"; 48 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48_grey.png"; 49 | displayName = "Lambda invocation failure: " + functionName; 50 | } 51 | } 52 | 53 | @Override 54 | public String getIconFileName() { 55 | return iconFileName; 56 | } 57 | 58 | public String getBigIconFileName() { 59 | return bigIconFileName; 60 | } 61 | 62 | @Override 63 | public String getDisplayName() { 64 | return displayName; 65 | } 66 | 67 | @Override 68 | public String getUrlName() { 69 | return URL_NAME; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadAction.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import hudson.model.ProminentProjectAction; 30 | 31 | public class LambdaUploadAction implements ProminentProjectAction { 32 | 33 | //Nothing to show, go to console for now 34 | private static final String URL_NAME = "console"; 35 | 36 | private final String iconFileName; 37 | private final String bigIconFileName; 38 | private final String displayName; 39 | 40 | 41 | public LambdaUploadAction(String functionName, Boolean success) { 42 | if(success){ 43 | iconFileName = "/plugin/aws-lambda/images/Lambda_24.png"; 44 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48.png"; 45 | displayName = "Deployed Lambda: " + functionName; 46 | }else { 47 | iconFileName = "/plugin/aws-lambda/images/Lambda_24_grey.png"; 48 | bigIconFileName = "/plugin/aws-lambda/images/Lambda_48_grey.png"; 49 | displayName = "Lambda deployment failure: " + functionName; 50 | } 51 | } 52 | 53 | @Override 54 | public String getIconFileName() { 55 | return iconFileName; 56 | } 57 | 58 | public String getBigIconFileName() { 59 | return bigIconFileName; 60 | } 61 | 62 | @Override 63 | public String getDisplayName() { 64 | return displayName; 65 | } 66 | 67 | @Override 68 | public String getUrlName() { 69 | return URL_NAME; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvoker.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.xti.jenkins.plugin.awslambda.exception.LambdaInvokeException; 30 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 31 | import com.xti.jenkins.plugin.awslambda.service.JsonPathParser; 32 | import com.xti.jenkins.plugin.awslambda.service.LambdaInvokeService; 33 | 34 | import java.io.IOException; 35 | import java.util.HashMap; 36 | import java.util.Map; 37 | 38 | public class LambdaInvoker { 39 | 40 | private LambdaInvokeService lambda; 41 | private JenkinsLogger logger; 42 | 43 | public LambdaInvoker(LambdaInvokeService lambda, JenkinsLogger logger) { 44 | this.lambda = lambda; 45 | this.logger = logger; 46 | } 47 | 48 | public LambdaInvocationResult invoke(InvokeConfig config) throws IOException, InterruptedException { 49 | JsonPathParser jsonPathParser = new JsonPathParser(config.getJsonParameters(), logger); 50 | logger.log("%nStarting lambda invocation."); 51 | String output = null; 52 | try { 53 | output = lambda.invokeLambdaFunction(config); 54 | Map injectables = jsonPathParser.parse(output); 55 | 56 | return new LambdaInvocationResult(true, injectables); 57 | } catch (LambdaInvokeException e) { 58 | logger.log(e.getMessage()); 59 | return new LambdaInvocationResult(false, new HashMap()); 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/util/LambdaClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.util; 2 | 3 | import com.amazonaws.ClientConfiguration; 4 | import com.amazonaws.auth.BasicAWSCredentials; 5 | import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; 6 | import com.amazonaws.regions.Region; 7 | import com.amazonaws.regions.Regions; 8 | import com.amazonaws.services.lambda.AWSLambdaClient; 9 | import hudson.ProxyConfiguration; 10 | 11 | import java.io.Serializable; 12 | 13 | public class LambdaClientConfig implements Serializable { 14 | private String region; 15 | private String accessKeyId; 16 | private String secretKey; 17 | private Boolean useDefaultAWSCredentials; 18 | private ProxyConfiguration proxyConfiguration; 19 | 20 | public LambdaClientConfig(String region, ProxyConfiguration proxyConfiguration){ 21 | this.region = region; 22 | this.useDefaultAWSCredentials = true; 23 | this.proxyConfiguration = proxyConfiguration; 24 | } 25 | 26 | public LambdaClientConfig(String accessKeyId, String secretKey, String region, ProxyConfiguration proxyConfiguration) { 27 | this.region = region; 28 | this.accessKeyId = accessKeyId; 29 | this.secretKey = secretKey; 30 | this.useDefaultAWSCredentials = false; 31 | this.proxyConfiguration = proxyConfiguration; 32 | } 33 | 34 | public AWSLambdaClient getClient() { 35 | if(useDefaultAWSCredentials){ 36 | return new AWSLambdaClient(new DefaultAWSCredentialsProviderChain(), getClientConfiguration()) 37 | .withRegion(Region.getRegion(Regions.fromName(region))); 38 | } else { 39 | return new AWSLambdaClient(new BasicAWSCredentials(accessKeyId, secretKey), getClientConfiguration()) 40 | .withRegion(Region.getRegion(Regions.fromName(region))); 41 | } 42 | } 43 | 44 | private ClientConfiguration getClientConfiguration() { 45 | /* 46 | Jenkins instance = Jenkins.getInstance(); 47 | 48 | if (instance != null) { 49 | ProxyConfiguration proxy = instance.proxy; 50 | */ 51 | ClientConfiguration config = new ClientConfiguration(); 52 | 53 | if (proxyConfiguration != null) { 54 | config.setProxyHost(proxyConfiguration.name); 55 | config.setProxyPort(proxyConfiguration.port); 56 | if (proxyConfiguration.getUserName() != null) { 57 | config.setProxyUsername(proxyConfiguration.getUserName()); 58 | config.setProxyPassword(proxyConfiguration.getPassword()); 59 | } 60 | if (proxyConfiguration.noProxyHost != null) { 61 | config.setNonProxyHosts(proxyConfiguration.noProxyHost); 62 | } 63 | } 64 | 65 | return config; 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/service/LambdaInvokeService.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.service; 2 | 3 | import com.amazonaws.services.lambda.AWSLambdaClient; 4 | import com.amazonaws.services.lambda.model.InvocationType; 5 | import com.amazonaws.services.lambda.model.InvokeRequest; 6 | import com.amazonaws.services.lambda.model.InvokeResult; 7 | import com.amazonaws.services.lambda.model.LogType; 8 | import com.amazonaws.util.Base64; 9 | import com.xti.jenkins.plugin.awslambda.exception.LambdaInvokeException; 10 | import com.xti.jenkins.plugin.awslambda.invoke.InvokeConfig; 11 | import org.apache.commons.lang.StringUtils; 12 | 13 | import java.nio.charset.Charset; 14 | 15 | public class LambdaInvokeService { 16 | private AWSLambdaClient client; 17 | private JenkinsLogger logger; 18 | 19 | public LambdaInvokeService(AWSLambdaClient client, JenkinsLogger logger) { 20 | this.client = client; 21 | this.logger = logger; 22 | } 23 | 24 | /** 25 | * Synchronously or asynchronously invokes an AWS Lambda function. 26 | * If synchronously invoked, the AWS Lambda log is collected and the response payload is returned 27 | * @param invokeConfig AWS Lambda invocation configuration 28 | * @return response payload 29 | */ 30 | public String invokeLambdaFunction(InvokeConfig invokeConfig) throws LambdaInvokeException { 31 | InvokeRequest invokeRequest = new InvokeRequest() 32 | .withFunctionName(invokeConfig.getFunctionName()) 33 | .withPayload(invokeConfig.getPayload()); 34 | 35 | if(invokeConfig.isSynchronous()){ 36 | invokeRequest 37 | .withInvocationType(InvocationType.RequestResponse) 38 | .withLogType(LogType.Tail); 39 | } else { 40 | invokeRequest 41 | .withInvocationType(InvocationType.Event); 42 | } 43 | logger.log("Lambda invoke request:%n%s%nPayload:%n%s%n", invokeRequest.toString(), invokeConfig.getPayload()); 44 | 45 | InvokeResult invokeResult = client.invoke(invokeRequest); 46 | String payload = ""; 47 | if(invokeResult.getPayload() != null){ 48 | payload = new String(invokeResult.getPayload().array(), Charset.forName("UTF-8")); 49 | } 50 | logger.log("Lambda invoke response:%n%s%nPayload:%n%s%n", invokeResult.toString(), payload); 51 | 52 | if(invokeResult.getLogResult() != null){ 53 | logger.log("Log:%n%s%n", new String(Base64.decode(invokeResult.getLogResult()), Charset.forName("UTF-8"))); 54 | } 55 | 56 | if(StringUtils.isNotEmpty(invokeResult.getFunctionError())){ 57 | throw new LambdaInvokeException("Function returned error of type: " + invokeResult.getFunctionError()); 58 | } 59 | 60 | return payload; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/upload/EnvironmentConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import com.xti.jenkins.plugin.awslambda.util.ExpansionUtils; 4 | import hudson.EnvVars; 5 | import hudson.Extension; 6 | import hudson.model.AbstractDescribableImpl; 7 | import hudson.model.Descriptor; 8 | import org.kohsuke.stapler.DataBoundConstructor; 9 | import org.kohsuke.stapler.DataBoundSetter; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | public class EnvironmentConfiguration extends AbstractDescribableImpl { 17 | 18 | private boolean configureEnvironment = false; 19 | private List environment = new ArrayList<>(); 20 | private String kmsArn; 21 | 22 | @DataBoundConstructor 23 | public EnvironmentConfiguration(List environment){ 24 | this.environment = environment; 25 | } 26 | 27 | public boolean isConfigureEnvironment() { 28 | return configureEnvironment; 29 | } 30 | 31 | @DataBoundSetter 32 | public void setConfigureEnvironment(boolean configureEnvironment) { 33 | this.configureEnvironment = configureEnvironment; 34 | } 35 | 36 | public List getEnvironment() { 37 | return environment; 38 | } 39 | 40 | public Map getMapRepresentation(){ 41 | Map environmentMap = new HashMap<>(); 42 | for (EnvironmentEntry environmentEntry : environment) { 43 | environmentMap.put(environmentEntry.getKey(), environmentEntry.getValue()); 44 | } 45 | return environmentMap; 46 | } 47 | 48 | public String getKmsArn() { 49 | return kmsArn; 50 | } 51 | 52 | @DataBoundSetter 53 | public void setKmsArn(String kmsArn) { 54 | this.kmsArn = kmsArn; 55 | } 56 | 57 | public void expandVariables(EnvVars env) { 58 | kmsArn = ExpansionUtils.expand(kmsArn, env); 59 | for (EnvironmentEntry environmentEntry : environment) { 60 | environmentEntry.expandVariables(env); 61 | } 62 | } 63 | 64 | public EnvironmentConfiguration getClone(){ 65 | List environmentEntries = new ArrayList<>(); 66 | if(environment != null) { 67 | for (EnvironmentEntry environmentEntry : environment) { 68 | environmentEntries.add(environmentEntry.getClone()); 69 | } 70 | } 71 | EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(environmentEntries); 72 | environmentConfiguration.setConfigureEnvironment(configureEnvironment); 73 | environmentConfiguration.setKmsArn(kmsArn); 74 | return environmentConfiguration; 75 | } 76 | 77 | @Extension 78 | public static class DescriptorImpl extends Descriptor { 79 | public String getDisplayName() { return ""; } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishVariablesTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.amazonaws.services.lambda.AWSLambda; 4 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 5 | import hudson.EnvVars; 6 | import hudson.util.Secret; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.jvnet.hudson.test.JenkinsRule; 11 | import org.mockito.runners.MockitoJUnitRunner; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertNotNull; 15 | 16 | /** 17 | * Created by Magnus Sulland on 4/08/2016. 18 | */ 19 | 20 | @RunWith(MockitoJUnitRunner.class) 21 | public class LambdaPublishVariablesTest { 22 | 23 | @Rule 24 | public JenkinsRule j = new JenkinsRule(); 25 | 26 | @Test 27 | public void testCloneExpandVariables() throws Exception { 28 | LambdaPublishVariables variables = new LambdaPublishVariables(false, "${ENV_ID}", Secret.fromString("$ENV_SECRET}}"), "${ENV_REGION}", "${ENV_ARN}", "${ENV_ALIAS}", "description ${ENV_VERSIONDESCRIPTION}"); 29 | LambdaPublishVariables clone = variables.getClone(); 30 | 31 | EnvVars envVars = new EnvVars(); 32 | envVars.put("ENV_ID", "ID"); 33 | envVars.put("ENV_SECRET", "SECRET"); 34 | envVars.put("ENV_REGION", "eu-west-1"); 35 | envVars.put("ENV_ARN", "ARN"); 36 | envVars.put("ENV_ALIAS", "ALIAS"); 37 | envVars.put("ENV_VERSIONDESCRIPTION", "DESCRIPTION"); 38 | clone.expandVariables(envVars); 39 | 40 | LambdaPublishVariables expected = new LambdaPublishVariables(false, "ID", Secret.fromString("$ENV_SECRET}}"), "eu-west-1", "ARN", "ALIAS", "description DESCRIPTION"); 41 | 42 | assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); 43 | assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); 44 | assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); 45 | assertEquals(expected.getFunctionARN(), clone.getFunctionARN()); 46 | assertEquals(expected.getFunctionAlias(), clone.getFunctionAlias()); 47 | assertEquals(expected.getVersionDescription(), clone.getVersionDescription()); 48 | } 49 | 50 | @Test 51 | public void testGetPublishConfig() throws Exception { 52 | LambdaPublishVariables variables = new LambdaPublishVariables("eu-west-1", "ARN", "ALIAS", "DESCRIPTION"); 53 | PublishConfig publishConfig = variables.getPublishConfig(); 54 | 55 | assertEquals(variables.getFunctionAlias(), publishConfig.getFunctionAlias()); 56 | assertEquals(variables.getFunctionARN(), publishConfig.getFunctionARN()); 57 | assertEquals(variables.getVersionDescription(), publishConfig.getVersionDescription()); 58 | } 59 | 60 | @Test 61 | public void testGetLambdaClientConfig() throws Exception { 62 | LambdaPublishVariables variables = new LambdaPublishVariables(false, "KEY", Secret.fromString("SECRET}"), "eu-west-1", "ARN", "ALIAS", "DESCRIPTION"); 63 | variables.expandVariables(new EnvVars()); 64 | LambdaClientConfig lambdaClientConfig = variables.getLambdaClientConfig(); 65 | 66 | AWSLambda lambda = lambdaClientConfig.getClient(); 67 | assertNotNull(lambda); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishBuildStepVariablesTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.amazonaws.services.lambda.AWSLambda; 4 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 5 | import hudson.EnvVars; 6 | import hudson.util.Secret; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.jvnet.hudson.test.JenkinsRule; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertNotNull; 13 | 14 | /** 15 | * Created by Magnus Sulland on 4/08/2016. 16 | */ 17 | 18 | public class LambdaPublishBuildStepVariablesTest { 19 | 20 | @Rule 21 | public JenkinsRule j = new JenkinsRule(); 22 | 23 | @Test 24 | public void testCloneExpandVariables() throws Exception { 25 | LambdaPublishBuildStepVariables variables = new LambdaPublishBuildStepVariables(false, "${ENV_ID}", Secret.fromString("$ENV_SECRET}}"), "${ENV_REGION}", "${ENV_ARN}", "${ENV_ALIAS}", "description ${ENV_VERSIONDESCRIPTION}"); 26 | LambdaPublishBuildStepVariables clone = variables.getClone(); 27 | 28 | EnvVars envVars = new EnvVars(); 29 | envVars.put("ENV_ID", "ID"); 30 | envVars.put("ENV_SECRET", "SECRET"); 31 | envVars.put("ENV_REGION", "eu-west-1"); 32 | envVars.put("ENV_ARN", "ARN"); 33 | envVars.put("ENV_ALIAS", "ALIAS"); 34 | envVars.put("ENV_VERSIONDESCRIPTION", "DESCRIPTION"); 35 | clone.expandVariables(envVars); 36 | 37 | LambdaPublishBuildStepVariables expected = new LambdaPublishBuildStepVariables(false, "ID", Secret.fromString("$ENV_SECRET}}"), "eu-west-1", "ARN", "ALIAS", "description DESCRIPTION"); 38 | 39 | assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); 40 | assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); 41 | assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); 42 | assertEquals(expected.getFunctionARN(), clone.getFunctionARN()); 43 | assertEquals(expected.getFunctionAlias(), clone.getFunctionAlias()); 44 | assertEquals(expected.getVersionDescription(), clone.getVersionDescription()); 45 | } 46 | 47 | @Test 48 | public void testGetPublishConfig() throws Exception { 49 | LambdaPublishBuildStepVariables variables = new LambdaPublishBuildStepVariables(false, "ID", Secret.fromString("SECRET}"), "eu-west-1", "ARN", "ALIAS", "DESCRIPTION"); 50 | PublishConfig publishConfig = variables.getPublishConfig(); 51 | 52 | assertEquals(variables.getFunctionARN(), publishConfig.getFunctionARN()); 53 | assertEquals(variables.getVersionDescription(), publishConfig.getVersionDescription()); 54 | assertEquals(variables.getFunctionAlias(), publishConfig.getFunctionAlias()); 55 | } 56 | 57 | @Test 58 | public void testGetLambdaClientConfig() throws Exception { 59 | LambdaPublishBuildStepVariables variables = new LambdaPublishBuildStepVariables(false, "ID", Secret.fromString("SECRET}"), "eu-west-1", "ARN", "ALIAS", "DESCRIPTION"); 60 | variables.expandVariables(new EnvVars()); 61 | LambdaClientConfig lambdaClientConfig = variables.getLambdaClientConfig(); 62 | 63 | AWSLambda lambda = lambdaClientConfig.getClient(); 64 | assertNotNull(lambda); 65 | } 66 | } -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploaderTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.upload; 2 | 3 | import com.amazonaws.services.lambda.model.FunctionCode; 4 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 5 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 6 | import com.xti.jenkins.plugin.awslambda.service.WorkSpaceZipper; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.Mock; 10 | import org.mockito.runners.MockitoJUnitRunner; 11 | 12 | import java.io.File; 13 | import java.util.ArrayList; 14 | 15 | import static org.junit.Assert.assertFalse; 16 | import static org.junit.Assert.assertTrue; 17 | import static org.mockito.Matchers.any; 18 | import static org.mockito.Mockito.*; 19 | 20 | @RunWith(MockitoJUnitRunner.class) 21 | public class LambdaUploaderTest { 22 | 23 | @Mock 24 | private LambdaDeployService service; 25 | 26 | @Mock 27 | private WorkSpaceZipper zipper; 28 | 29 | @Mock 30 | private JenkinsLogger logger; 31 | 32 | 33 | @Test 34 | public void testUploadSuccess() throws Exception { 35 | DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList(), new ArrayList()); 36 | File file = new File("path"); 37 | 38 | when(zipper.getZip(any(String.class))).thenReturn(file); 39 | when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class))) 40 | .thenReturn(true); 41 | 42 | LambdaUploader uploader = new LambdaUploader(service, zipper, logger); 43 | Boolean uploaded = uploader.upload(deployConfig); 44 | 45 | verify(logger, times(1)).log("%nStarting lambda deployment procedure"); 46 | verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full)); 47 | assertTrue(uploaded); 48 | } 49 | 50 | @Test 51 | public void testUploadFailure() throws Exception { 52 | DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList(), new ArrayList()); 53 | File file = new File("path"); 54 | 55 | when(zipper.getZip(any(String.class))).thenReturn(file); 56 | when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class))) 57 | .thenReturn(false); 58 | 59 | LambdaUploader uploader = new LambdaUploader(service, zipper, logger); 60 | Boolean uploaded = uploader.upload(deployConfig); 61 | 62 | verify(logger, times(1)).log("%nStarting lambda deployment procedure"); 63 | verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full)); 64 | assertFalse(uploaded); 65 | } 66 | 67 | @Test 68 | public void testUploadNoArtifact() throws Exception { 69 | DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList(), new ArrayList()); 70 | 71 | when(zipper.getZip(any(String.class))).thenReturn(null); 72 | when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class))) 73 | .thenReturn(true); 74 | 75 | LambdaUploader uploader = new LambdaUploader(service, zipper, logger); 76 | Boolean uploaded = uploader.upload(deployConfig); 77 | 78 | verify(logger, times(1)).log("%nStarting lambda deployment procedure"); 79 | verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full)); 80 | assertTrue(uploaded); 81 | } 82 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishPublisher.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.xti.jenkins.plugin.awslambda.publish.LambdaPublishServiceResponse; 4 | import com.xti.jenkins.plugin.awslambda.callable.PublishCallable; 5 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 6 | import hudson.Extension; 7 | import hudson.Launcher; 8 | import hudson.model.*; 9 | import hudson.tasks.BuildStepDescriptor; 10 | import hudson.tasks.BuildStepMonitor; 11 | import hudson.tasks.Notifier; 12 | import hudson.tasks.Publisher; 13 | import net.sf.json.JSONObject; 14 | import org.kohsuke.stapler.DataBoundConstructor; 15 | import org.kohsuke.stapler.StaplerRequest; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | /** 21 | * Project: aws-lambda 22 | * Created by Magnus Sulland on 26/07/2016. 23 | */ 24 | public class LambdaPublishPublisher extends Notifier { 25 | 26 | List lambdaPublishVariablesList = new ArrayList<>(); 27 | 28 | @DataBoundConstructor 29 | public LambdaPublishPublisher(List lambdaPublishVariablesList) { 30 | this.lambdaPublishVariablesList = lambdaPublishVariablesList; 31 | } 32 | 33 | public List getLambdaPublishVariablesList() { 34 | return lambdaPublishVariablesList; 35 | } 36 | 37 | public void setLambdaPublishVariablesList(List lambdaPublishVariablesList) { 38 | this.lambdaPublishVariablesList = lambdaPublishVariablesList; 39 | } 40 | 41 | @Override 42 | public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { 43 | boolean returnValue = true; 44 | 45 | if(lambdaPublishVariablesList != null) { 46 | for(LambdaPublishVariables variables : lambdaPublishVariablesList) { 47 | returnValue = returnValue && perform(variables, build, launcher, listener); 48 | } 49 | } 50 | return returnValue; 51 | } 52 | 53 | public boolean perform(LambdaPublishVariables variables, AbstractBuild build, Launcher launcher, 54 | BuildListener listener) { 55 | try { 56 | LambdaPublishVariables executionVariables = variables.getClone(); 57 | executionVariables.expandVariables(build.getEnvironment(listener)); 58 | PublishConfig publishConfig = executionVariables.getPublishConfig(); 59 | LambdaClientConfig clientConfig = executionVariables.getLambdaClientConfig(); 60 | 61 | PublishCallable publishCallable = new PublishCallable(listener, publishConfig, clientConfig); 62 | 63 | LambdaPublishServiceResponse lambdaRepsonse = launcher.getChannel().call(publishCallable); 64 | 65 | if(!lambdaRepsonse.getSuccess()){ 66 | build.setResult(Result.FAILURE); 67 | } 68 | 69 | build.addAction(new LambdaPublishAction(lambdaRepsonse.getFunctionVersion(), lambdaRepsonse.getFunctionAlias(), lambdaRepsonse.getSuccess())); 70 | return true; 71 | } catch (Exception exc) { 72 | throw new RuntimeException(exc); 73 | } 74 | } 75 | 76 | @Override 77 | public BuildStepMonitor getRequiredMonitorService() { 78 | return BuildStepMonitor.BUILD; 79 | } 80 | 81 | @Override 82 | public BuildStepDescriptor getDescriptor() { 83 | return (LambdaPublishPublisher.DescriptorImpl)super.getDescriptor(); 84 | } 85 | 86 | @Extension 87 | public static final class DescriptorImpl extends BuildStepDescriptor { 88 | 89 | public DescriptorImpl() { 90 | load(); 91 | } 92 | 93 | public boolean isApplicable(Class aClass) { 94 | return true; 95 | } 96 | 97 | public String getDisplayName() { 98 | return "AWS Lambda publish new version and update alias"; 99 | } 100 | 101 | @Override 102 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 103 | req.bindJSON(this, formData); 104 | 105 | save(); 106 | 107 | return super.configure(req,formData); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/invoke/JsonParameterVariables.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | /* 4 | * #%L 5 | * AWS Lambda Upload Plugin 6 | * %% 7 | * Copyright (C) 2015 XT-i 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import com.xti.jenkins.plugin.awslambda.util.ExpansionUtils; 30 | import hudson.EnvVars; 31 | import hudson.Extension; 32 | import hudson.model.AbstractDescribableImpl; 33 | import hudson.model.Descriptor; 34 | import hudson.util.FormValidation; 35 | import org.apache.commons.lang.StringUtils; 36 | import org.kohsuke.stapler.DataBoundConstructor; 37 | import org.kohsuke.stapler.DataBoundSetter; 38 | import org.kohsuke.stapler.QueryParameter; 39 | 40 | public class JsonParameterVariables extends AbstractDescribableImpl { 41 | private String envVarName; 42 | private String jsonPath; 43 | 44 | @DataBoundConstructor 45 | public JsonParameterVariables(String envVarName) { 46 | this.envVarName = envVarName; 47 | } 48 | 49 | @Deprecated 50 | public JsonParameterVariables(String envVarName, String jsonPath) { 51 | this.envVarName = envVarName; 52 | this.jsonPath = jsonPath; 53 | } 54 | 55 | public String getEnvVarName() { 56 | return envVarName; 57 | } 58 | 59 | public String getJsonPath() { 60 | return jsonPath; 61 | } 62 | 63 | @DataBoundSetter 64 | public void setJsonPath(String jsonPath) { 65 | this.jsonPath = jsonPath; 66 | } 67 | 68 | public JsonParameter buildJsonParameter(){ 69 | return new JsonParameter(envVarName, jsonPath); 70 | } 71 | 72 | public void expandVariables(EnvVars env) { 73 | envVarName = ExpansionUtils.expand(envVarName, env); 74 | jsonPath = ExpansionUtils.expand(jsonPath, env); 75 | } 76 | 77 | @Extension // This indicates to Jenkins that this is an implementation of an extension point. 78 | public static class DescriptorImpl extends Descriptor { 79 | 80 | /** 81 | * This human readable name is used in the configuration screen. 82 | */ 83 | public String getDisplayName() { 84 | return "Environment Variable"; 85 | } 86 | 87 | //envVarName field 88 | public FormValidation doCheckEnvVarName(@QueryParameter String value) { 89 | if(StringUtils.isEmpty(value)){ 90 | return FormValidation.error("Please fill in name of environment variable."); 91 | } else { 92 | return FormValidation.ok(); 93 | } 94 | } 95 | 96 | } 97 | 98 | @Override 99 | public boolean equals(Object o) { 100 | if (this == o) return true; 101 | if (o == null || getClass() != o.getClass()) return false; 102 | 103 | JsonParameterVariables that = (JsonParameterVariables) o; 104 | 105 | if (envVarName != null ? !envVarName.equals(that.envVarName) : that.envVarName != null) return false; 106 | return !(jsonPath != null ? !jsonPath.equals(that.jsonPath) : that.jsonPath != null); 107 | 108 | } 109 | 110 | @Override 111 | public int hashCode() { 112 | int result = envVarName != null ? envVarName.hashCode() : 0; 113 | result = 31 * result + (jsonPath != null ? jsonPath.hashCode() : 0); 114 | return result; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeVariablesTest.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.invoke; 2 | 3 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 4 | import hudson.EnvVars; 5 | import hudson.util.Secret; 6 | import org.junit.Rule; 7 | import org.junit.Test; 8 | import org.jvnet.hudson.test.JenkinsRule; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertNotNull; 15 | 16 | public class LambdaInvokeVariablesTest { 17 | 18 | @Rule 19 | public JenkinsRule j = new JenkinsRule(); 20 | 21 | @Test 22 | public void testCloneExpandVariables() throws Exception { 23 | List jsonParameterVariables = new ArrayList(); 24 | jsonParameterVariables.add(new JsonParameterVariables("ENV_$ENV_ENV_NAME", "$.$ENV_JSON_PATH")); 25 | LambdaInvokeVariables variables = new LambdaInvokeVariables(false, "${ENV_ID}", Secret.fromString("$ENV_SECRET}"), "${ENV_REGION}", "${ENV_FUNCTION}", "${\"payload\":\"${ENV_PAYLOAD}\"", true, true, jsonParameterVariables); 26 | LambdaInvokeVariables clone = variables.getClone(); 27 | 28 | EnvVars envVars = new EnvVars(); 29 | envVars.put("ENV_ID", "ID"); 30 | envVars.put("ENV_SECRET", "SECRET"); 31 | envVars.put("ENV_REGION", "eu-west-1"); 32 | envVars.put("ENV_FUNCTION", "FUNCTION"); 33 | envVars.put("ENV_PAYLOAD", "hello"); 34 | envVars.put("ENV_ENV_NAME", "NAME"); 35 | envVars.put("ENV_JSON_PATH", "path"); 36 | envVars.put(".", "bad"); 37 | clone.expandVariables(envVars); 38 | 39 | List jsonParameterVariablesExpected = new ArrayList(); 40 | jsonParameterVariablesExpected.add(new JsonParameterVariables("ENV_NAME", "$.path")); 41 | LambdaInvokeVariables expected = new LambdaInvokeVariables(false, "ID", Secret.fromString("$ENV_SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariablesExpected); 42 | 43 | assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); 44 | assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); 45 | assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); 46 | assertEquals(expected.getFunctionName(), clone.getFunctionName()); 47 | assertEquals(expected.getPayload(), clone.getPayload()); 48 | assertEquals(expected.getSynchronous(), clone.getSynchronous()); 49 | assertEquals(expected.getSuccessOnly(), clone.getSuccessOnly()); 50 | assertEquals(expected.getJsonParameters().get(0).getEnvVarName(), clone.getJsonParameters().get(0).getEnvVarName()); 51 | assertEquals(expected.getJsonParameters().get(0).getJsonPath(), clone.getJsonParameters().get(0).getJsonPath()); 52 | } 53 | 54 | @Test 55 | public void testGetInvokeConfig() throws Exception { 56 | List jsonParameterVariables = new ArrayList(); 57 | jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); 58 | LambdaInvokeVariables variables = new LambdaInvokeVariables(false, "ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariables); 59 | InvokeConfig invokeConfig = variables.getInvokeConfig(); 60 | 61 | assertEquals(variables.getFunctionName(), invokeConfig.getFunctionName()); 62 | assertEquals(variables.getPayload(), invokeConfig.getPayload()); 63 | assertEquals(variables.getSynchronous(), invokeConfig.isSynchronous()); 64 | assertEquals(variables.getJsonParameters().get(0).getEnvVarName(), invokeConfig.getJsonParameters().get(0).getEnvVarName()); 65 | assertEquals(variables.getJsonParameters().get(0).getJsonPath(), invokeConfig.getJsonParameters().get(0).getJsonPath()); 66 | } 67 | 68 | @Test 69 | public void testGetLambdaClientConfig() throws Exception { 70 | List jsonParameterVariables = new ArrayList(); 71 | jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); 72 | LambdaInvokeVariables variables = new LambdaInvokeVariables(false, "ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariables); 73 | 74 | LambdaClientConfig clientConfig = variables.getLambdaClientConfig(); 75 | assertNotNull(clientConfig); 76 | } 77 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.jenkins-ci.plugins 5 | plugin 6 | 1.580.1 7 | 8 | 9 | aws-lambda 10 | 0.6.0-SNAPSHOT 11 | hpi 12 | 13 | AWS Lambda Plugin 14 | 15 | This plugin adds AWS Lambda invocation and deployment abilities to build steps and post build actions 16 | 17 | https://wiki.jenkins-ci.org/display/JENKINS/AWS+Lambda+Plugin 18 | 19 | 20 | 21 | MIT License 22 | http://www.opensource.org/licenses/mit-license.php 23 | 24 | 25 | 26 | 2015 27 | 28 | 29 | scm:git:https://github.com/jenkinsci/aws-lambda-plugin.git 30 | scm:git:https://github.com/jenkinsci/aws-lambda-plugin.git 31 | https://github.com/jenkinsci/aws-lambda-plugin 32 | aws-lambda-0.5.3 33 | 34 | 35 | 36 | XT-i 37 | http://www.xt-i.com 38 | 39 | 40 | 41 | 42 | cast 43 | Michael Willemse 44 | 45 | 46 | 47 | 48 | 1.11.64 49 | 2.0.0 50 | 51 | 52 | 53 | 54 | com.amazonaws 55 | aws-java-sdk-core 56 | ${aws.version} 57 | 58 | 59 | com.amazonaws 60 | aws-java-sdk-lambda 61 | ${aws.version} 62 | 63 | 64 | com.jayway.jsonpath 65 | json-path 66 | ${jsonpath.version} 67 | 68 | 69 | org.jenkins-ci.plugins 70 | structs 71 | 1.6 72 | 73 | 74 | org.hamcrest 75 | hamcrest-core 76 | 1.3 77 | test 78 | 79 | 80 | org.mockito 81 | mockito-core 82 | 1.10.19 83 | test 84 | 85 | 86 | 87 | 88 | 89 | 90 | src/main/resources 91 | true 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-compiler-plugin 98 | 3.3 99 | 100 | 1.7 101 | 1.7 102 | 103 | 104 | 105 | org.codehaus.mojo 106 | license-maven-plugin 107 | 1.5 108 | 109 | mit 110 | 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-release-plugin 115 | 2.5.2 116 | 117 | 118 | 119 | 120 | 121 | 122 | repo.jenkins-ci.org 123 | https://repo.jenkins-ci.org/public/ 124 | 125 | 126 | 127 | 128 | 129 | repo.jenkins-ci.org 130 | https://repo.jenkins-ci.org/public/ 131 | 132 | 133 | 134 | 135 | 136 | maven.jenkins-ci.org 137 | https://repo.jenkins-ci.org/releases 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/publish/LambdaPublishBuildStep.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.publish; 2 | 3 | import com.xti.jenkins.plugin.awslambda.callable.PublishCallable; 4 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 5 | import hudson.Extension; 6 | import hudson.FilePath; 7 | import hudson.Launcher; 8 | import hudson.model.AbstractProject; 9 | import hudson.model.Result; 10 | import hudson.model.Run; 11 | import hudson.model.TaskListener; 12 | import hudson.tasks.BuildStepDescriptor; 13 | import hudson.tasks.BuildStepMonitor; 14 | import hudson.tasks.Builder; 15 | import jenkins.tasks.SimpleBuildStep; 16 | import net.sf.json.JSONObject; 17 | import org.jenkinsci.Symbol; 18 | import org.kohsuke.stapler.DataBoundConstructor; 19 | import org.kohsuke.stapler.StaplerRequest; 20 | 21 | import javax.annotation.Nonnull; 22 | import java.io.IOException; 23 | 24 | /** 25 | * Project: aws-lambda 26 | * Created by Magnus Sulland on 26/07/2016. 27 | */ 28 | public class LambdaPublishBuildStep extends Builder implements SimpleBuildStep { 29 | private LambdaPublishBuildStepVariables lambdaPublishBuildStepVariables; 30 | 31 | @DataBoundConstructor 32 | public LambdaPublishBuildStep(LambdaPublishBuildStepVariables lambdaPublishBuildStepVariables) { 33 | this.lambdaPublishBuildStepVariables = lambdaPublishBuildStepVariables; 34 | } 35 | 36 | public LambdaPublishBuildStepVariables getLambdaPublishBuildStepVariables() { 37 | return this.lambdaPublishBuildStepVariables; 38 | } 39 | 40 | public void setLambdaPublishBuildStepVariables(LambdaPublishBuildStepVariables lambdaPublishBuildStepVariables){ 41 | this.lambdaPublishBuildStepVariables = lambdaPublishBuildStepVariables; 42 | } 43 | 44 | @Override 45 | public void perform(@Nonnull Run run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { 46 | perform(lambdaPublishBuildStepVariables, run, launcher, listener); 47 | } 48 | 49 | public void perform(LambdaPublishBuildStepVariables lambdaPublishBuildStepVariables, Run run, Launcher launcher, TaskListener listener) { 50 | try { 51 | LambdaPublishBuildStepVariables executionVariables = lambdaPublishBuildStepVariables.getClone(); 52 | executionVariables.expandVariables(run.getEnvironment(listener)); 53 | PublishConfig publishConfig = executionVariables.getPublishConfig(); 54 | LambdaClientConfig clientConfig = executionVariables.getLambdaClientConfig(); 55 | 56 | PublishCallable publishCallable = new PublishCallable(listener, publishConfig, clientConfig); 57 | 58 | LambdaPublishServiceResponse lambdaSuccess = launcher.getChannel().call(publishCallable); 59 | 60 | if(!lambdaSuccess.getSuccess()){ 61 | run.setResult(Result.FAILURE); 62 | } 63 | 64 | run.addAction(new LambdaPublishAction(lambdaSuccess.getFunctionVersion(), lambdaSuccess.getFunctionAlias(), lambdaSuccess.getSuccess())); 65 | } catch(Exception exc) { 66 | throw new RuntimeException(exc); 67 | } 68 | } 69 | 70 | public BuildStepMonitor getRequiredMonitorService() { 71 | return BuildStepMonitor.NONE; 72 | } 73 | 74 | // Overridden for better type safety. 75 | // If your plugin doesn't really define any property on Descriptor, 76 | // you don't have to do this. 77 | @SuppressWarnings("unchecked") 78 | @Override 79 | public BuildStepDescriptor getDescriptor() { 80 | return (LambdaPublishBuildStep.DescriptorImpl)super.getDescriptor(); 81 | } 82 | 83 | @Extension // This indicates to Jenkins that this is an implementation of an extension point. 84 | @Symbol("publishLambda") 85 | public static final class DescriptorImpl extends BuildStepDescriptor { 86 | 87 | public DescriptorImpl() { 88 | load(); 89 | } 90 | 91 | @SuppressWarnings("rawtypes") 92 | public boolean isApplicable(Class aClass) { 93 | // Indicates that this builder can be used with all kinds of project types 94 | return true; 95 | } 96 | 97 | /** 98 | * This human readable name is used in the configuration screen. 99 | */ 100 | public String getDisplayName() { 101 | return "AWS Lambda publish new version and update alias"; 102 | } 103 | 104 | @Override 105 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 106 | req.bindJSON(this, formData); 107 | 108 | save(); 109 | 110 | return super.configure(req,formData); 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadBuildStepVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 |
72 |
73 | 74 |
-------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadVariables/config.jelly: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 |
69 |
70 | 71 |
-------------------------------------------------------------------------------- /src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourcePublisher.java: -------------------------------------------------------------------------------- 1 | package com.xti.jenkins.plugin.awslambda.eventsource; 2 | 3 | import com.xti.jenkins.plugin.awslambda.callable.EventSourceCallable; 4 | import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; 5 | import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; 6 | import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; 7 | import hudson.Extension; 8 | import hudson.Launcher; 9 | import hudson.model.AbstractBuild; 10 | import hudson.model.AbstractProject; 11 | import hudson.model.BuildListener; 12 | import hudson.model.Result; 13 | import hudson.tasks.BuildStepDescriptor; 14 | import hudson.tasks.BuildStepMonitor; 15 | import hudson.tasks.Notifier; 16 | import hudson.tasks.Publisher; 17 | import net.sf.json.JSONObject; 18 | import org.kohsuke.stapler.DataBoundConstructor; 19 | import org.kohsuke.stapler.StaplerRequest; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by anthonyikeda on 25/11/2015. 26 | */ 27 | public class LambdaEventSourcePublisher extends Notifier { 28 | 29 | List lambdaEventSourceVariablesList = new ArrayList<>(); 30 | 31 | @DataBoundConstructor 32 | public LambdaEventSourcePublisher(List lambdaEventSourceVariablesList) { 33 | this.lambdaEventSourceVariablesList = lambdaEventSourceVariablesList; 34 | } 35 | 36 | public List getLambdaEventSourceVariablesList() { 37 | return lambdaEventSourceVariablesList; 38 | } 39 | 40 | public void setLambdaEventSourceVariablesList(List lambdaEventSourceVariablesList) { 41 | this.lambdaEventSourceVariablesList = lambdaEventSourceVariablesList; 42 | } 43 | 44 | @Override 45 | public boolean perform(AbstractBuild build, Launcher launcher, 46 | BuildListener listener) { 47 | boolean returnValue = true; 48 | 49 | if(lambdaEventSourceVariablesList != null) { 50 | for(LambdaEventSourceVariables variables : lambdaEventSourceVariablesList) { 51 | returnValue = returnValue && perform(variables, build, launcher, listener); 52 | } 53 | } 54 | return returnValue; 55 | } 56 | 57 | public boolean perform(LambdaEventSourceVariables variables, AbstractBuild build, Launcher launcher, 58 | BuildListener listener) { 59 | if(variables.getSuccessOnly() && build.getResult().isWorseThan(Result.SUCCESS)) { 60 | listener.getLogger().println("Build not successful, not applying event source to Lambda function: " + variables.getFunctionName()); 61 | return true; 62 | } else if(!variables.getSuccessOnly() && build.getResult().isWorseThan(Result.UNSTABLE)) { 63 | listener.getLogger().println("Build failed, not applying event source to Lambda function: " + variables.getFunctionName()); 64 | return true; 65 | } 66 | 67 | try { 68 | LambdaEventSourceVariables executionVariables = variables.getClone(); 69 | executionVariables.expandVariables(build.getEnvironment(listener)); 70 | EventSourceConfig eventSourceConfig = executionVariables.getEventSourceConfig(); 71 | LambdaClientConfig clientConfig = executionVariables.getLambdaClientConfig(); 72 | 73 | EventSourceCallable eventSourceCallable = new EventSourceCallable(listener, eventSourceConfig, clientConfig); 74 | 75 | Boolean lambdaSuccess = launcher.getChannel().call(eventSourceCallable); 76 | 77 | if(!lambdaSuccess){ 78 | build.setResult(Result.FAILURE); 79 | } 80 | 81 | build.addAction(new LambdaEventSourceAction(executionVariables.getFunctionName(), lambdaSuccess)); 82 | return true; 83 | } catch (Exception exc) { 84 | throw new RuntimeException(exc); 85 | } 86 | } 87 | 88 | @Override 89 | public BuildStepMonitor getRequiredMonitorService() { 90 | return BuildStepMonitor.BUILD; 91 | } 92 | 93 | @Override 94 | public BuildStepDescriptor getDescriptor() { 95 | return (DescriptorImpl) super.getDescriptor(); 96 | } 97 | 98 | @Extension 99 | public static final class DescriptorImpl extends BuildStepDescriptor { 100 | public DescriptorImpl() { 101 | load(); 102 | } 103 | 104 | @Override 105 | public String getDisplayName() { 106 | return "AWS Lambda Event Source Mapper"; 107 | } 108 | 109 | public boolean isApplicable(Class aClass) { 110 | return true; 111 | } 112 | 113 | @Override 114 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 115 | req.bindJSON(this, formData); 116 | 117 | save(); 118 | 119 | return super.configure(req,formData); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/resources/com/xti/jenkins/plugin/awslambda/tags/awsLambdaOptionalBlock.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 |