I'm setting up a build pipeline in azure devops. There's an assistant task called YarnInstaller@3 that allows me to install a specific version of Yarn. However, the only available versions listed are 1.x, with the latest being 1.22.
There are migration instructions at https://yarnpkg.com/getting-started/install for migrating from v1 to v2+, which I've done locally. Since only yarn@1.x is available, it seems like I'll have to migrate every time I run a build, e.g.
This seems unnecessary, especially since I've already committed the .yarnrc.yml
and the .yarn
sub-directories. Am I wrong about that? Is there another way to install yarn@2+ in my pipeline?
You can use the following command lines in your pipeline to update the version of Yarn to 2.x
.
yarn set version berry
yarn set version 2.x
For more details, you can see:
Below is the sample pipeline I tested on my side, and it can work as expected. You can reference it and add the related steps in your build pipeline.
steps:
. . .
- task: Bash@3
displayName: 'Yarn version before update'
inputs:
targetType: inline
script: |
echo "Yarn version before update:"
yarn --version
- task: Bash@3
displayName: 'Update Yarn version to 2.x'
inputs:
targetType: inline
script: |
yarn set version berry
yarn set version 2.x
- task: Bash@3
displayName: 'Yarn version after update'
inputs:
targetType: inline
script: |
echo "Yarn version after update:"
yarn --version