简体   繁体   中英

How to trigger STDERR on release pipelines in Azure Devops

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?

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 (eg [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. (eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM