This is demonstration how to make basic CI/CD pipeline setup using Jenkins and SonarQube in GCP.
- Make sure terraform exist in OS path. To test, type
which terraform
. - In terminal, create new file
terraform.tfvars
.
project = "project_id" # set your GCP progect id
region = "us-central1"
zone = "us-central1-c"
size = "n1-standard-2"
public_key = ".key/user.pub"
private_key = ".key/user.pem"
master_user = "user"
master_pass = "abcdefghij123" # password must be at least 16 characters
app_repo = "https://github.com/incubus8/gcp-cicd-terraform-jenkins.git"
- create ssh key
ssh-keygen -f user.pem -N""
# leave an empty password - rename public to
.pub
- place both in
.key
subdir
- enable Kubernetes Engine API by visiting service console
- Console -> IAM & admin -> Service accounts -> select default account (or create new) -> Edit -> Create Key -> Json
- place the service account key file into the
.key/account.json
- In terminal, type
terraform init
, thenterraform apply
- Login to build server http://{terraform.output.build}:8080/
- Create SERVICE_ACCOUNT_KEY secret file (Jenkins -> Credentials -> Global Credentials -> Add Credentials)
- SERVICE_ACCOUNT_KEY { type = secret file } For secrets file, use '.key/account.json'
- Create new project using
pipeline
template and pastejenkins/Jenkinsfile
content - Manage Jenkins -> Manage Plugins -> Available -> filter: sonar -> SonarQube Scanner for Jenkins -> Install and restart
- Manage Jenkins -> Configure System -> SonarQube servers -> Add SonarQube -> Name: sonar, Host: http://{terraform.output.sonar}:9000 -> Save
- Manage Jenkins -> Global Tool Configuration -> Add SonarQube Scanner -> Name: scanner -> Save
- Enable Poll SCM, if CI mode is required
- App url
http://{terraform.output.app}:5000
- Jenkins URL server
http://{terraform.output.build}:8080
- SonarQube
http://{terraform.output.sonar}:9000
In terminal, type:
terraform destroy
This is just a demo pipeline. You may want to setup more strict security if you want to apply in production.
- Deploy using Kubernetes Control Plane
Jakarta (c) 2019