azure-devopsazure-pipelines-yaml

Alternatives for gnu tar when using cache@2 task in 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!


Solution

  • 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.