forked from eficode/cicd-code-scan-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
42 lines (33 loc) · 1.94 KB
/
bootstrap.sh
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
#!/bin/bash
GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD:=password}
JENKINS_ADMIN_USER=${JENKINS_ADMIN_USER:=jenkins}
JENKINS_ADMIN_PASSWORD=${JENKINS_ADMIN_PASSWORD:=password}
SONARQUBE_SERVER_NAME=${SONARQUBE_SERVER_NAME:=sonarqube.local.net}
JENKINS_SERVER_NAME=${JENKINS_SERVER_NAME:=jenkins.local.net}
GTILAB_SERVER_NAME=${GITLAB_SERVER_NAME:=gitlab.local.net}
set -e
# Get needed ENV variables
source ./sourceme
# Bring up the containers
docker-compose up -d
# SonarQube ready?
echo "Waiting for SonarQube to come up..."
while [[ "`curl -s -f -u admin:admin http://${SONARQUBE_SERVER_NAME}/api/system/status | sed -n 's|.*"status":"\([^"]*\)".*|\1|p'`" != "UP" ]]; do
sleep 2
done;
# Create Jenkins user
echo "Creating Jenkins user and webhook..."
curl -s -u admin:admin -X POST http://$SONARQUBE_SERVER_NAME/api/users/create\?login\=$JENKINS_ADMIN_USER\&local\=true\&name\=$JENKINS_ADMIN_USER\&password\=$JENKINS_ADMIN_PASSWORD > /dev/null 2>&1
curl -s -u admin:admin -X POST http://$SONARQUBE_SERVER_NAME/api/user_groups/add_user\?login\=$JENKINS_ADMIN_USER\&name\=sonar-administrators > /dev/null 2>&1
curl -s -u admin:admin -X POST http://$SONARQUBE_SERVER_NAME/api/webhooks/create\?name\=jenkins\&url\="http://jenkins.local.net/sonarqube-webhook/" > /dev/null 2>&1
# Create a token for the jenkins user
TOKEN=`curl -s -u admin:admin -X POST http://$SONARQUBE_SERVER_NAME/api/user_tokens/generate\?login\=$JENKINS_ADMIN_USER\&name\=jenkins | sed -n 's|.*"token":"\([^"]*\)".*|\1|p'`
echo "Use this token value in Jenkins credential 'token-sonarqube': $TOKEN"
# Must wait for gitlab to become healthy
echo "Waiting for gitlab to be healthy. Be patient, may take a few minutes."
while [[ "`docker inspect -f {{.State.Health.Status}} gitlab`" != "healthy" ]]; do
sleep 2
done;
# When healthy push this repository.
echo "Pushing DevSecOps demo to gitlab."
git push --set-upstream http://root:[email protected]/root/devsecops-demo.git master