Sunday, 6 October 2019

Running mocha test with Azure pipelines and Docker

I am very new to CICD.

I have an Azure web app running a Docker container built from an Express Nodejs image.

My current flow is minimalistic. I have an Azure-pipelines.yml file that looks like

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'    

- task: AzureCLI@1
  inputs:
    azureSubscription: 'xxxxxx'
    scriptLocation: 'inlineScript'
    inlineScript: 'az acr build --registry registry123 --image image123:latest --file Dockerfile .'

And a dockerfile that looks like

FROM node:10

WORKDIR /poc/microservices

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD [ "node", "server.js" ]

Now I have added some mocha tests that I can run with npm test, and these are running fine locally.

Now I want to add these to the pipeline so that it doesnt build the image if the tests are failing.

I have a mocha.opts file where I defined --reporter mocha-junit-reporter and the tests are using an process.env.ENDPOINT variable.

So my question is how do I add the command to the pipeline?

Do I simply add

- script: npm install
- script: npm test

to azure-pipelines.yml and then configure the ENDPOINT variable in the build variables in azure devOps portal?

If so, is it not a problem that I am running then twice npm install? once in Azure, and another time in Docker?



from Running mocha test with Azure pipelines and Docker

No comments:

Post a Comment