0

We have an angular app which has some e2e tests on it. We create a standalone docker image with the e2e tests, one for the app.

When we deploy the app, using azure devops release pipelines, we have a poststep, after deploy that should run the e2e tests.

We run these commands:

az container create --resource-group $(DEV_RG) --name $(E2E_IMAGE_NAME) --image $(E2E_IMAGE_REGISTRY) --registry-username $(REGISTRY_USERNAME) --registry-password $(REGISTRY_PASSWORD) --vnet $(VNET_LOCATION) --subnet $(E2E_SUBNET) --subnet-address-prefix $(E2E_IP_GROUP) --command-line ./rune2e.sh 

Then, we want to see the output:

az container logs --resource-group $(DEV_RG) --name $(E2E_IMAGE_NAME)

I've also tried

az container attach --resource-group $(DEV_RG) --name $(E2E_IMAGE_NAME)

No matter what happens in those logs, the step is always green.

How can I catch the stderr event that the container is outputting, and marking the step red in Azure devops?

petur
  • 1,366
  • 3
  • 21
  • 42

2 Answers2

1

Docker container logs are both stdout/stderr on the same stream, therefore you cannot make a distinction when looking at them using the az container logs command.

There would be two approaches you could take

1) grep for known keywords that your error logs would have (e.g. [ERROR]) if there is some STDERR or error logs you would like to fail on

2) update your process inside the docker container (or the entrypoint of the container) to redirect it stderr stream to a local file in the container. (e.g. start.sh 2> stderr.log) After your pipeline runs the E2E, simple run a tasks to run the az container exec and check if there was any logs written to the stderr.log inside the container.

In both cases, you should return a non 0 exit code to force your pipeline to fail.

djsly
  • 1,522
  • 11
  • 13
  • I'm using the Azure CLI task right now, it seams that doesn't support to grep and launch scripts? I have to use the Bash task in the pipeline to achieve this? – petur Apr 30 '20 at 07:48
  • correct, you will need to use a BASH task to get better control on the custom script you need to execute – djsly Apr 30 '20 at 15:43
  • It was not possible to use Bash, somehow the service principal that makes us able to deploy to our cloud didn't support it. – petur May 01 '20 at 13:11
1

I ended up adding this to the Azure CLI task that logs the container.

#!/bin/bash

az container logs --resource-group $(DEV_RG) --name  $(E2E_IMAGE_NAME) --only-show-errors | grep Error\:

if [ $? -eq 0 ]
then
  echo "Failure: I found error in file. Test failed."
  exit 1
else
  echo "Success: I did not find error in file. Test passed." >&2
  exit 0
fi
petur
  • 1,366
  • 3
  • 21
  • 42
  • Much appreciate your solution shared here. It would be much great if you can accept this answer, then others can direct know this worked method:-) – Mengdi Liang May 04 '20 at 01:50