-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#171182749] Created Azure DevOps pipeline #14
Conversation
azure-pipelines.yml
Outdated
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vmImage: 'ubuntu-latest' | |
vmImage: 'windows-2019' |
since we are deploying on azure functions windows runtime, probably it's better to use a windows vm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gunzip I tried to run the pipeline with vmImage: 'windows-2019'
but several syntax errors occurred.
For instance, in the Build step of the compile job (stage: Build_check), this is the result of the execution of the yarn build
command:
Starting: Build
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.163.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
yarn build
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\79a3529b-5427-4b37-80f3-c82ead3bf936.cmd""
yarn run v1.21.1
$ yarn generate:definitions && tsc
$ rimraf ./generated/definitions && mkdir -p ./generated/definitions && gen-api-models --api-spec ./openapi/index.yaml --out-dir ./generated/definitions
The syntax of the command is incorrect.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Cmd.exe exited with code '1'.
Finishing: Build
Do you have any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try using "bash" instead of "script" ?
ie.
steps:
- bash: |
yarn ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already tried using bash
but without success! It's not enough...
After many attempts, I have found the root cause of the problems... In the packege.json
file there is the definition of some scripts used in the pipeline:
{
"name": "io-functions-admin",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "yarn generate:definitions && tsc",
"build:production": "npm run prestart && npm prune --production",
"watch": "tsc --w",
"prestart": "npm run build && func extensions install",
"start:host": "func start",
"start": "npm-run-all --parallel start:host watch",
"test": "jest",
"test:coverage": "jest --coverage",
"lint": "tslint -p .",
"deploy": "npm run build && func azure functionapp publish agid-functions-admin-test",
"generate:definitions": "rimraf ./generated/definitions && mkdir -p ./generated/definitions && gen-api-models --api-spec ./openapi/index.yaml --out-dir ./generated/definitions"
},
- bash: |
yarn build
displayName: 'Build'
The yarn build
command fails when running in a Windows bash for the following reasons:
mkdir -p
is not supported&&
can be used only one time (i.e. cmd1 && cmd2 is ok but cmd1 && cmd2 && cmd3 fails)
So, it seems that there are some limitations when executing a bash script on Azure pipelines... I could easily solve the problem avoiding re-using the scripts defined in the packege.json
, for instance changing the above job in the pipeline with the following:
- bash: |
mkdir ./generated && mkdir ./generated/definitions
yarn gen-api-models --api-spec ./openapi/index.yaml --out-dir ./generated/definitions
yarn tsc
displayName: 'Build'
In this way, the pipeline runs without problems both in 'ubuntu-latest' and 'windows-2019' and we only need to take into account that developers could use little different scripts to build the code in their local environments.
I also notice that the pipeline execution time is different:
- vmImage: 'ubuntu-latest' takes about 50s
- vmImage: 'windows-2019' takes about 1m 20s
If all the above limitations are reasonable I can proceed with the specified changes to run the pipeline in Windows vm.
@gunzip what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the insight @raicastino ! IMHO it's a duty of the package owners to maintain compatibility. As we run everything inside a windows VM we must make package.json tasks cross platform. There are some techniques:
- using shx to run shell commands
- cross-env to use enviroment variables
- use npm-run-all with subtasks instead of &&
If you want, you may try to do this inside another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gunzip Following your suggestions:
- I changed vmImage from 'ubuntu-latest' to 'windows-2019'
- Changed the package.json file to make a script cross-platform (using shx)
- For the build job I used in the pipeline the script defined in the package.json (yarn build)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great ! can we test a deploy into the staging environment ? (how ? do we have to create an azure pipeline service connection ? in which account ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this pipeline will be a replace of the current pipeline based on CircleCI. I need permissions on GitHub to enable this pipeline. By the way, only the CI part is currently implemented...
Example of PR titles that include pivotal stories:
New dependencies added: shxAuthor: Unknown Description: Portable Shell Commands for Node Homepage: https://github.com/shelljs/shx#readme
|
Unsupported command | Recommend workaround |
---|---|
shx cd |
Just use plain old cd (it's the same on windows too) |
shx pushd |
Just use plain old pushd . Use forward slashes and double-quote the path. (e.g. pushd "../docs" . This would fail on Windows without the quotes) |
shx popd |
Just use plain old popd |
shx dirs |
No workaround |
shx set |
See below |
shx exit |
Just use plain old exit |
shx exec |
Instead of shx exec cmd , just use plain old cmd |
shx ShellString |
No workaround (but why would you want this?) |
Shx options
Shx allows you to modify its behavior by passing arguments. Here's a list of
supported options:
set flag |
shell.config setting |
shx command | Effect |
---|---|---|---|
-e |
config.fatal = true |
Not supported | Exit upon first error |
-v |
config.verbose = true |
shx --verbose cd foo |
Log the command as it's run |
-f |
config.noglob = true |
shx --noglob cat '*.txt' |
Don't expand wildcards |
N/A | config.silent = true |
shx --silent cd noexist |
Don't show error output |
Team
Nate Fischer | Ari Porad | Levi Thomason |
Generated by 🚫 dangerJS
This is an Azure DevOps pipeline to build, check source codes, run tests, and more.
This pipeline has been implemented to be run on hosted agent pools based both on 'windows-2019' and 'ubuntu-latest' virtual machine images and using the scripts defined in the package.json file.