File tree Expand file tree Collapse file tree 4 files changed +48
-12
lines changed
charts/pipelines-library/templates/tasks/sonar Expand file tree Collapse file tree 4 files changed +48
-12
lines changed Original file line number Diff line number Diff line change @@ -82,14 +82,23 @@ spec:
82
82
script : |
83
83
set -e
84
84
85
- PROJECT_EXISTS =$(curl -s -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}" | jq -r ".component.key ")
85
+ SONAR_RESPONSE =$(curl -s -u " ${SONAR_TOKEN}:" "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}")
86
86
87
- if [ "$PROJECT_EXISTS" == "null" ]; then
87
+ if [[ -z "$SONAR_RESPONSE" ]]; then
88
+ echo "Token isn't valid or not defined"
89
+ exit 1
90
+ fi
91
+
92
+ if echo "$SONAR_RESPONSE" | jq -e '.errors[0].msg' &>/dev/null; then
88
93
default_branch=$(kubectl get codebase $SONAR_PROJECT_NAME -o jsonpath='{.spec.defaultBranch}')
89
94
echo "Create project ${SONAR_PROJECT_KEY}"
90
95
curl -X POST -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/projects/create?name=${SONAR_PROJECT_KEY}&project=${SONAR_PROJECT_KEY}&mainBranch=${default_branch}"
91
96
else
92
- echo "Project ${SONAR_PROJECT_KEY} already exists"
97
+ if echo "$SONAR_RESPONSE" | jq -e '.component.key' &>/dev/null; then
98
+ echo "Project \"$SONAR_PROJECT_KEY\" already exists"
99
+ else
100
+ echo "Unknown Response format"
101
+ fi
93
102
fi
94
103
- name : sonar-scanner
95
104
image : $(params.BASE_IMAGE)
Original file line number Diff line number Diff line change @@ -72,14 +72,23 @@ spec:
72
72
script : |
73
73
set -e
74
74
75
- PROJECT_EXISTS =$(curl -s -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}" | jq -r ".component.key ")
75
+ SONAR_RESPONSE =$(curl -s -u " ${SONAR_TOKEN}:" "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}")
76
76
77
- if [ "$PROJECT_EXISTS" == "null" ]; then
77
+ if [[ -z "$SONAR_RESPONSE" ]]; then
78
+ echo "Token isn't valid or not defined"
79
+ exit 1
80
+ fi
81
+
82
+ if echo "$SONAR_RESPONSE" | jq -e '.errors[0].msg' &>/dev/null; then
78
83
default_branch=$(kubectl get codebase $SONAR_PROJECT_NAME -o jsonpath='{.spec.defaultBranch}')
79
84
echo "Create project ${SONAR_PROJECT_KEY}"
80
85
curl -X POST -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/projects/create?name=${SONAR_PROJECT_KEY}&project=${SONAR_PROJECT_KEY}&mainBranch=${default_branch}"
81
86
else
82
- echo "Project ${SONAR_PROJECT_KEY} already exists"
87
+ if echo "$SONAR_RESPONSE" | jq -e '.component.key' &>/dev/null; then
88
+ echo "Project \"$SONAR_PROJECT_KEY\" already exists"
89
+ else
90
+ echo "Unknown Response format"
91
+ fi
83
92
fi
84
93
- image : registry.access.redhat.com/ubi8/ubi-minimal:8.8
85
94
name : prepare-sonar-project-properties
Original file line number Diff line number Diff line change @@ -90,14 +90,23 @@ spec:
90
90
script : |
91
91
set -e
92
92
93
- PROJECT_EXISTS =$(curl -s -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}" | jq -r ".component.key ")
93
+ SONAR_RESPONSE =$(curl -s -u " ${SONAR_TOKEN}:" "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}")
94
94
95
- if [ "$PROJECT_EXISTS" == "null" ]; then
95
+ if [[ -z "$SONAR_RESPONSE" ]]; then
96
+ echo "Token isn't valid or not defined"
97
+ exit 1
98
+ fi
99
+
100
+ if echo "$SONAR_RESPONSE" | jq -e '.errors[0].msg' &>/dev/null; then
96
101
default_branch=$(kubectl get codebase $SONAR_PROJECT_NAME -o jsonpath='{.spec.defaultBranch}')
97
102
echo "Create project ${SONAR_PROJECT_KEY}"
98
103
curl -X POST -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/projects/create?name=${SONAR_PROJECT_KEY}&project=${SONAR_PROJECT_KEY}&mainBranch=${default_branch}"
99
104
else
100
- echo "Project ${SONAR_PROJECT_KEY} already exists"
105
+ if echo "$SONAR_RESPONSE" | jq -e '.component.key' &>/dev/null; then
106
+ echo "Project \"$SONAR_PROJECT_KEY\" already exists"
107
+ else
108
+ echo "Unknown Response format"
109
+ fi
101
110
fi
102
111
- name : gradle-tasks
103
112
image : $(params.BASE_IMAGE)
Original file line number Diff line number Diff line change @@ -95,14 +95,23 @@ spec:
95
95
script : |
96
96
set -e
97
97
98
- PROJECT_EXISTS =$(curl -s -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}" | jq -r ".component.key ")
98
+ SONAR_RESPONSE =$(curl -s -u " ${SONAR_TOKEN}:" "${SONAR_HOST_URL}/api/components/show?component=${SONAR_PROJECT_KEY}")
99
99
100
- if [ "$PROJECT_EXISTS" == "null" ]; then
100
+ if [[ -z "$SONAR_RESPONSE" ]]; then
101
+ echo "Token isn't valid or not defined"
102
+ exit 1
103
+ fi
104
+
105
+ if echo "$SONAR_RESPONSE" | jq -e '.errors[0].msg' &>/dev/null; then
101
106
default_branch=$(kubectl get codebase $SONAR_PROJECT_NAME -o jsonpath='{.spec.defaultBranch}')
102
107
echo "Create project ${SONAR_PROJECT_KEY}"
103
108
curl -X POST -u ${SONAR_TOKEN}: "${SONAR_HOST_URL}/api/projects/create?name=${SONAR_PROJECT_KEY}&project=${SONAR_PROJECT_KEY}&mainBranch=${default_branch}"
104
109
else
105
- echo "Project ${SONAR_PROJECT_KEY} already exists"
110
+ if echo "$SONAR_RESPONSE" | jq -e '.component.key' &>/dev/null; then
111
+ echo "Project \"$SONAR_PROJECT_KEY\" already exists"
112
+ else
113
+ echo "Unknown Response format"
114
+ fi
106
115
fi
107
116
- name : mvn-goals
108
117
image : $(params.MAVEN_IMAGE)
You can’t perform that action at this time.
0 commit comments