0

I have a pipeline that always fail with a shell command. This is:

response=$(curl -s -u "${HARBOR_SWIO_USER}:${HARBOR_SWIO_PASS}" -H "Accept:application/json" "$URL")

#This line will fail
echo "$response" | jq -e --arg TAG "$TAG" '.[]|select(.tags[].name==$TAG)' > /dev/null

if [ $? -eq 0 ]; then
    echo "Image exists"
else
    echo "Image does not exist"
fi

I put this into a shell script on my Linux and execute it, works well. On Gitlab with a Linux Runner it fails.

I checked the jq version, both 1.6 I verified the JSON from response with JQ and this is successful (0).

echo $response | jq -e . >/dev/null 2>&1  ; echo ${PIPESTATUS[1]}

But everytime the first call fail on Gitlab. Any Idea what is wrong?

1
  • Use if echo "$response" | jq -e ...; then directly, without trying to use $?; the if will cause errexit / set -e (turned on by gitlab by default) to be suppressed, but only for the condition it contains. Commented Nov 20, 2024 at 17:21

1 Answer 1

-2

response=$(curl -s -u "${HARBOR_SWIO_USER}:${HARBOR_SWIO_PASS}" -H "Accept:application/json" "$URL")

#This line will fail echo "$response" | jq -e --arg TAG "$TAG" '.[]|select(.tags[].name==$TAG)' > /dev/null

if [ $? -eq 0 ]; then echo "Image exists" else echo "Image does not exist"

Sign up to request clarification or add additional context in comments.

2 Comments

How does this answer the question?
I do not understand the answer, sorry.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.