Alternatives for gnu tar when using cache#2 task in Azure DevOps - azure-devops

I'm having a hard time getting cache#2 task working as it seems when the build agent is windows OS, it requires to have GNU Tar installed in the machine and this seems it doesnt seem to be an option right now. This needs to run in the windows machine as its part of a stage and requires to collect the build output to produce the artifact.
Somewhere I read this could be an option but it doesn't work and its not on Microsoft's documentation: tool: '7zip'
- task: Cache#2
displayName: Restore from cache
inputs:
key: 'npm | "$(Agent.OS)" | $(projectDir)package-lock.json'
#restoreKeys: |
# npm | "$(Agent.OS)"
path: $(Pipeline.Workspace)/.npm
cacheHitVar: CACHE_RESTORED
verbose: true
- script: |
npm install
displayName: Install dependencies #, Build and Lint
workingDirectory: $(projectDir)
condition: ne(variables.CACHE_RESTORED, 'true')
The log says: ##[error]Failed to start the required dependency 'tar'. Please verify the correct version is installed and available on the path. This is accurate but I was wondering if there's any workaround or if I just can have the cache implemented and I have to install all dependencies on each run.
Btw, I'm using the default pool and its using windows v10.0.14393 and agent version 2.206.1
Thanks!

If it helps to anyone, I had to split my workflow into API and FE stages. The angular stage would run in the ubuntu agent that would have the tar installed. That fixed my problem and I also had the 2 stages running in parallel.

Related

Azure Pipelines: Where is the output of my script?

I tried to build my Angular 13 app on a self-hosted agent and created the following YAML snippet for this:
- task: NodeTool#0
displayName: 'Install Node.js'
inputs:
versionSpec: '14.x'
- script: |
npm install -g #angular/cli
npm install
ng build --configuration production --aot
displayName: 'npm install and build'
workingDirectory: '$(Build.SourcesDirectory)/src'
I can observe the /s directory of the agent _work-directory and after my task was running, there is no node_modules folder or dist folder inside.
But also no console output.
If I remove the line "npm install -g #angular/cli" from the line, a node_modules folder gets created, but no dist-folder.
I am pretty sure that the installation of angular cli fails, but I do not get any error output in my window.
It just looks like this:
How can I get more logs to find out why the angular cli is not installing correctly? I saw that the "script" file that is executed on the agent puts an #echo off by default in front of the script.
Why is that?
How can I get some output to find my problem?
To get more detailed log from the pipeline you can add the variable system.debug and set the value to true in your pipeline.
For YAML pipelines, you can select Variables in the upper right corner of the YAML edit page.
Add a new variable with the name System.Debug and value true.
For more info about logs, please refer to Review logs to diagnose pipeline issues.

A task is missing. The pipeline references a task called 'UsePythonVersion'. This usually indicates the task isn't installed,

i am new to Azure DevOps and have been trying to run a simple task in azure-pipelines.yml CI pipeline.
- stage: Test
jobs:
- job: Pytest
displayName: Pytest
pool:
vmImage: ($vmImageName)
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: '3.8'
- bash: pytest
- bash: find ./tests/ -type f -name "*.py" | xargs pylint --jobs=2
However, i get the error for the task UsePythonVersion and also for Bash :
A task is missing. The pipeline references a task called 'UsePythonVersion'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. (Task version 0, job 'Pytest', step ''.)
A task is missing. The pipeline references a task called 'Bash'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. (Task version 0, job 'Pytest', step ''.)
I tried looking for these on the Marketplace as well, but no clue.
Any leads here would be helpful
Thanks, actually the case was that Disable built-in tasks in organization Settings was enabled.
One can find it in Organizations Setting - > Pipelines -> Settings -> Tasks Restrictions -> Disable built-in tasks
The task's own documentation says:
Prerequisites
A Microsoft-hosted agent with side-by-side versions of
Python installed, or a self-hosted agent with Agent.ToolsDirectory
configured (see FAQ).
This task will fail if no Python versions are
found in Agent.ToolsDirectory. Available Python versions on
Microsoft-hosted agents can be found here.
Perhaps your agent does not have those prerequisites?

Running bash script within a project folder of AzureDevOps

I have a script that is nicely performing all kinds of dependency installation and some manual works (NPM installation, some manual steps to do while setting up project) to setup a project before it is able to run. The script runs perfectly fine in a local environment.
Im now trying to build my pipeline in Azure DevOps, I realized I can't just fire the script right away. Running npm install inside the script is not actually running within my project folder but it always runs on the path /Users/runner/work
Question:
How can I execute the script within my project folder?
Sample code in my script file
set -e
# Setup project dependencies
npm install
# some mandatory manual work
.....
# Pod installation
cd ios
pod install
My AzurePipelines.yml
- task: Bash#3
inputs:
targetType: 'inline'
script: |
sh $(System.DefaultWorkingDirectory)/projectFolder/setup.sh
failOnStderr: true
Issue log from Azure (as you can see, the npm installation is not working due to incorrect path, hence further actions within pipeline will fail)
npm WARN saveError ENOENT: no such file or directory, open '/Users/runner/work/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/runner/work/package.json'
npm WARN work No description
npm WARN work No repository field.
npm WARN work No README data
npm WARN work No license field.
Firstly I'd advise you to split your script into different steps of a single job or multiple jobs with many steps because this makes it easier to parallel them in the future allowing you to speed up the build time.
In order to execute your script directly from the project folder you can leverage the option working directory:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
./setup.sh
failOnStderr: true
workingDirectory: "$(System.DefaultWorkingDirectory)/projectFolder/"
However in your case you could point directly to the script, without the need to run it as a "script"
- task: Bash#3
inputs:
targetType: 'filePath'
filePath: "$(System.DefaultWorkingDirectory)/projectFolder/setup.sh"
failOnStderr: true
workingDirectory: "$(System.DefaultWorkingDirectory)/projectFolder/"
ref.: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops

Inconsistent output in YAML pipeline vs default Azure Pipeline

I'm trying to run a "dotnet tool install" to install cli tool on the build agent in my pipeline and the behavior is inconsistent. Sometimes it executes the command successfully but it also fails sometimes with below error and I cannot figure out why however the same step executes successfully when i use azure default pipeline instead of YAML based.
error NU1212: Invalid project-package combination for project 1.0.0. DotnetToolReference project style can only contain references of the DotnetTool type The tool package could not be restored. Tool 'project' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
Here is the task:
- task: DotNetCoreCLI#2
displayName: 'Install project'
inputs:
command: custom
custom: tool
arguments: 'install -g --version 1.0.0 --add-source https://sample.jfrog.io/artifactory/project project'
Command:
dotnet tool install -g --version 1.0.0 --add-source https://sample.jfrog.io/artifactory/project project
These tasks are running on Windows-latest image on Microsoft Hosted agents

Azure pipelines yaml permission denied

I'm getting an error when trying to deploy using azure pipelines.
Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
I think its becuase the node_modules folder is not being shared between stages. But I cant figure out what is proper way to do it.
Here is my yaml file:
variables:
- group: netlify
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Build
jobs:
- job: ARM
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run unit
displayName: 'Setup and test'
- script: npm run build
- publish: $(System.DefaultWorkingDirectory)
artifact: dist
- stage: Deploy
dependsOn: Build
condition: succeeded()
jobs:
- job: APP
steps:
- bash: |
npm i -g netlify-cli
netlify deploy --site $(NETLIFY_SITE_ID) --auth $(NETLIFY_AUTH_TOKEN) --prod
After running npm install, package node_modules should appear somehwere in the directory but it seems its not properly shared.
You are using Ubuntu image, and trying to global install netlify-cli in Linux without sudo.
If the Ubuntu is the necessary system you must use, you'd better add sudo before this command:
sudo npm i -g netlify-cli
Command succeed on my pipeline
In this doc, Upgrading on *nix (OSX, Linux, etc.):
You may need to prefix these commands with sudo, especially on Linux,
or OS X if you installed Node using its default installer.
Same in VSTS, you must use sudo in the command to let you has password-less sudo rights for Ubuntu.
Another way is change the image to vs2017-win2016 if you do not has any special requirements for the build environment:
pool:
vmImage: 'vs2017-win2016'
When using this image, you could install anything and do not need use sudo.
In fact, we has been pre-installed many basic tools in all hosted images, including node.js
In our github description, we listed all tools that pre-installed for all images. You can check to know more about VSTS.