Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/retgits/jenkinsbuild-lambda
An AWS Lambda app that triggers Jenkins jobs based on SQS events
https://github.com/retgits/jenkinsbuild-lambda
aws-sqs jenkins lambda
Last synced: about 1 month ago
JSON representation
An AWS Lambda app that triggers Jenkins jobs based on SQS events
- Host: GitHub
- URL: https://github.com/retgits/jenkinsbuild-lambda
- Owner: retgits
- License: mit
- Created: 2018-06-09T20:33:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-11T21:14:25.000Z (over 5 years ago)
- Last Synced: 2024-11-08T21:58:29.561Z (3 months ago)
- Topics: aws-sqs, jenkins, lambda
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jenkinsbuild-lambda
Trigger builds using the [Jenkins REST API](https://wiki.jenkins.io/display/JENKINS/Remote+access+API) based on messages published on an [Amazon SQS](https://aws.amazon.com/sqs/) queue.
## Prerequisites
### Environment Variables
The app relies on [AWS Systems Manager Parameter Store](https://aws.amazon.com/systems-manager/features/) (SSM) to store encrypted variables on how to connect to Jenkins. The variables it relies on are:
* `/prod/jenkins/token`: The token to authenticate to Jenkins
* `/prod/jenkins/user`: The username to authenticate to Jenkins
* `/prod/jenkins/url`: The URL to JenkinsThese parameters are encrypted using [Amazon KMS](https://aws.amazon.com/kms/) and retrieved from the Parameter Store on deployment. This way the encrypted variables are given to the Lambda function and the function needs to take care of decrypting them at runtime.
To create the encrypted variables, run the below command for all of the variables
```bash
aws ssm put-parameter \
--type String \
--name "/prod/jenkins/token" \
--value $(aws kms encrypt \
--output text \
--query CiphertextBlob \
--key-id \
--plaintext "PLAIN TEXT HERE")
```To test the function locally, using `SAM`, you'll have to uncomment lines 45-47 in the `template.yaml` file and update these with base64 encoded values from the Parameter Store. Only during deployment to AWS Lambda will these variables get their actual values from the Parameter Store.
### SQS queue
The SSM parameter `/prod/jenkins/sqsqueue` doesn't have to be encrypted but does need to reference a valid SQS ARN. The payload of the message the function expects is
```json
{
"BuildID": "MyAwesomeBuild"
}
```In this case, _MyAwesomeBuild_ is the name of the job to trigger in Jenkins.
## Build and Deploy
There are several `Make` targets available to help build and deploy the function
| Target | Description |
|--------|---------------------------------------------------|
| build | Build the executable for Lambda |
| clean | Remove all generated files |
| deploy | Deploy the app to AWS Lambda |
| deps | Get the Go modules from the GOPROXY |
| help | Displays the help for each target (this message). |
| local | Run SAM to test the Lambda function using Docker |
| test | Run all unit tests and print coverage |