{"id":26115645,"url":"https://github.com/andreistefanciprian/jenkins_aws_codebuild","last_synced_at":"2026-04-09T18:03:55.389Z","repository":{"id":50166028,"uuid":"273664889","full_name":"andreistefanciprian/jenkins_aws_codebuild","owner":"andreistefanciprian","description":"trigger aws codebuild projects from Jenkinsfile","archived":false,"fork":false,"pushed_at":"2021-06-02T02:15:45.000Z","size":119,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-26T08:48:24.932Z","etag":null,"topics":["automation","codebuild","devops","jenkins","jenkinsfile","python","terraform","yaml"],"latest_commit_sha":null,"homepage":null,"language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreistefanciprian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-20T08:01:01.000Z","updated_at":"2020-11-08T17:42:43.000Z","dependencies_parsed_at":"2022-09-24T18:13:12.438Z","dependency_job_id":null,"html_url":"https://github.com/andreistefanciprian/jenkins_aws_codebuild","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fjenkins_aws_codebuild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fjenkins_aws_codebuild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fjenkins_aws_codebuild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fjenkins_aws_codebuild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreistefanciprian","download_url":"https://codeload.github.com/andreistefanciprian/jenkins_aws_codebuild/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242813468,"owners_count":20189280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","codebuild","devops","jenkins","jenkinsfile","python","terraform","yaml"],"created_at":"2025-03-10T07:56:33.648Z","updated_at":"2025-12-31T00:55:44.053Z","avatar_url":"https://github.com/andreistefanciprian.png","language":"HCL","readme":"## Description\n\nThis is a Jenkins pipeline that builds CodeBuild projects in AWS cloud, then runs these CodeBuild projects.\nThe CodeBuild projects are building infrastructure within AWS cloud.\n\nThe pipeline is doing the following:\n- build AWS resources with terraform (Codebuild projects)\n- parses yaml file with codebuild projects to be executed (python script)\n- starts each of the codebuild projects extracted from yaml file, one by one (python script)\n\n## Prerequisites\n\nHave Docker installed. We'll be running Jenkins on a Docker container.\n\nSpin off a Jenkins docker container with a named volume to preserve jenkins configuration and pipeline for future use:\n```docker-compose -f jenkins/docker-compose.yaml up --detach```\n\nAWS account at https://console.aws.amazon.com/.\nAWS access key and secret to be used by Terraform and Jenkins.\nAWS Role to be assumed by Terraform and Jenkins.\nAWS s3 bucket (terraform backend) and dynamodb table for terraform state lock management.\n\nCreate these resources following these steps:\n```\ncd prerequisites\nterraform init --var-file=\"../../terraform.tfvars\"\nterraform plan --var-file=\"../../terraform.tfvars\" -out terraform.tfplan\nterraform apply \"terraform.tfplan\"\n\n# or\n\ncd prerequisites\nterraform init --var-file=\"../../terraform.tfvars\"\nterraform apply -input=false -auto-approve --var-file=\"../../terraform.tfvars\"\n```\n\nFor the steps above, AWS access key and access secret key should be stored in a terraform.tfvars file.\nThere is a sample with the contents of this file in the main directory of the repository.\n\nOnce the prerequsites resources are built, the details of these resources will be shown in the terraform output.\nTake these details and populate the related fields in these files:\n- terraform_code/*/main.tf (tfstate s3 bucket and dynamodb table)\n- terraform_code/*/variables.tf (iam role arn)\n- terraform_code/.env (AWS acess key and secret)\n- buildspec.yaml (s3 bucket name)\n\n## Configure Jenkins and run pipeline\n\nGo through Jenkins installation steps at: http://localhost:8090. \n\nDefine these secrets in Jenkins:\n - aws_access_key: AWS_ACCESS_KEY_ID (secret text); created in prerequsites step\n - aws_secret_key: AWS_SECRET_ACCESS_KEY (secret text); created in prerequsites step\n - aws_region: AWS region (secret text)\n - aws_account: AWS account number (secret text)\n - Git token defined both as secret text and username and password type of secrets (used for git hook and git clone private repo)\n\nAWS credentials inside Codebuild projects:\n- .env file with AWS secrets (AWS_ACCESS_KEY_ID=acces-key and AWS_SECRET_ACCESS_KEY=secret-key generated in prerequsites step) should be made available in s3 bucket (check buildspec.yaml file)\n- terraform used by the CodeBuild projects is running inside a container (check docker-compose.yaml file)\n- the terraform credentials are provided as environment variables via the .env file (check docker-compose.yaml file)\n\nCreate Jenkins pipeline job with default settings using Pipeline script from SCM with URL https://github.com/andreistefanciprian/jenkins_aws_codebuild.git.\n\nRun pipeline job!\n\n## Destroy resources at the end of this tutorial\n```\n\n# destroy terraform s3 bucket and dynamodb table used for tfstate management\ncd prerequisites\nterraform destroy --var-file=\"../../terraform.tfvars\"\n\n# destroy AWS resources (AWS creds to be stored in .env file prior to run these commands)\ncd terraform_code\nmake destroy-auto-approve TF_TARGET=infra\nmake destroy-auto-approve TF_TARGET=static\nmake destroy-auto-approve TF_TARGET=codebuil\n\n# spin down Jenkins docker container:\ndocker-compose -f jenkins/docker-compose.yaml down\n```\n\n## Other debug commands\n\nUse these AWS CLI commands to manually interact with CodeBuild:\n```\n# list CodeBuild projects and builds\naws codebuild list-projects\naws codebuild list-builds\n\n# start CodeBuild project\naws codebuild start-build --project-name codebuildtest-MessageUtil\naws codebuild start-build --project-name newproj-test\n\n# list CodeBuild jobs for specific project\naws codebuild list-builds-for-project --project-name codebuildtest-MessageUtil\n\n# get last build for project\naws codebuild list-builds-for-project --project-name codebuildtest-MessageUtil --query 'ids[0]' --output text\n\naws codebuild batch-get-builds --ids codebuildtest-MessageUtil:f0682dfe-2d7e-4bec-8061-2008843089e7\n\n# query status of last Codebuild build\nbuild_id=$(aws codebuild list-builds-for-project --project-name codebuildtest-MessageUtil --query 'ids[0]' --output text)\naws codebuild batch-get-builds --ids $build_id --query 'builds[0].buildStatus' --output text\n```\n\nUse these commands to manually check python script:\n```\n# create python3 virtual env\npython3 -m venv .venv\n\n# activate environment\nsource .venv/bin/activate\n\n# install requirements\npip install -r requirements.txt\n\n# execute script\naws_account=9238748923565 \npython execute_codebuild_from_yaml.py $aws_account\n```\n\nUse these commands to verify you can build resources with terraform from CLI:\n```\nTF_VAR_TARGET=static\ndocker-compose run terraform init $TF_VAR_TARGET\ndocker-compose run terraform plan -out terraform.tfplan $TF_VAR_TARGET\ndocker-compose run terraform apply terraform.tfplan\ndocker-compose run terraform destroy -auto-approve $TF_VAR_TARGET\n\n# using make commands\nmake deploy-auto-approve TF_TARGET=$TF_VAR_TARGET\nmake destroy-auto-approve TF_TARGET=$TF_VAR_TARGET\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreistefanciprian%2Fjenkins_aws_codebuild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreistefanciprian%2Fjenkins_aws_codebuild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreistefanciprian%2Fjenkins_aws_codebuild/lists"}