9

I am using simple curl command as given in gitlab documents, to Post the build status to a commit .

But in gitlab build status it only shows:

"Pipeline #20 failed for abc....."

Even when I am passing "description", "target_url" attributes.

I have tried,

curl --request POST --header "PRIVATE-TOKEN: 9ko..." "https://gitlab.example.com/api/v4/projects/17/statuses/18f3...?state=failed&description=my_decsription&target_url=http://example.org/link"

From curl output in terminal, it is successfully passing all attributes. But in gitlab build status it only shows,

"Pipeline #20 failed for abc....." .

I want the output to be like,

"Pipeline #20 failed for abc..... my_description http://example.org/link".
OR
Any other format which supports 'description' and 'target_url' attributes.

I searched on Internet but not succeed. I am using gitlab 8.16.
Is there something which I need to add/configure in gitlab?

UPDATE: Actually the "target_url" which I am specifying is appeared as a hyper-link on specific build number of Build tab. But not appearing where I want it.
"description" is not appearing anywhere.

TPS
  • 493
  • 1
  • 5
  • 28
  • It's a POST so command should/could be `curl --request POST --header "PRIVATE-TOKEN: 9ko..." --data 'state=failed&description=my_decsription&target_url=http://example.org/link' "https://gitlab.example.com/api/v4/projects/17/statuses/18f3..."`. Request will be sent as `application/x-www-form-urlencoded`. Also seems you are missing `id` and `sha` required parameters. – LMC May 30 '18 at 12:56
  • Sorry, semicolon is missing `/projects/:17/statuses/:18f3...`. – LMC May 30 '18 at 13:03
  • There is no need of colon(if we add colon there is 404 ERROR of "project not found / commit not found ". And the command you have posted in 1st comment is equivalent to my command, there is no change in output. Please also look at my Update. – TPS May 31 '18 at 06:28

2 Answers2

0

It looks like target_url parameter only influences the link you are sent to, when you click on a build status label (see image below). To show it you need to manually add it to description as well:

curl --request POST --header "PRIVATE-TOKEN: XXXXXX" "https://gitlab.com/api/v4/projects/XXXXXX/statuses/67814f7489214e91738680b433679224993dc1c4?state=failed&name=some_label&description=some%20useful%20description_of_failure%20http://www.google.com&target_url=http://www.google.com"

If you want to see the description you have to go into commit details and roll your mouse over build status label:

enter image description here

gp42
  • 545
  • 3
  • 7
0

This works with gitlab 15.2.2

generate_post_data()
{
  cat <<EOF
  {
    "description": "$DESCRIPTION",
    "name": "$JOB_IDENTIFIER",
    "state": "$STATUS",
    "target_url": "$TARGET_URL"
  }
EOF
}

curl \
--request POST "https://your-gitlab-url.com/api/v4/projects/$PROJECT_ID/statuses/${GIT_COMMIT}" \
--header "PRIVATE-TOKEN: $PRIVATE_TOKEN" \
--header 'Content-Type: application/json' \
--fail \
--data "$(generate_post_data)" \
--include
Ted
  • 22,696
  • 11
  • 95
  • 109