microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.47k stars 2.6k forks source link

Azure File Copy build task not available on hosted Ubuntu build agent #8920

Open benne opened 5 years ago

benne commented 5 years ago

Environment

Issue Description

I got a project building some pulling from an external Git repository, and building it with gcc through a simple bash script - no problem. However, when I attempt to use the Azure File Copy task to copy over the single output file to a Azure Blob Storage container, I am told that this task won't run on Linux. Is there any plans to make Azure File Copy work on the hosted Ubuntu 16.04 build agent, or do you have any other suggestion on how to achieve the same result with existing tasks that will run on this hosted build server?

Error logs

2018-11-27T18:03:41.7033273Z ##[section]Starting: AzureBlob File Copy
2018-11-27T18:03:41.7038323Z ==============================================================================
2018-11-27T18:03:41.7038468Z Task         : Azure File Copy
2018-11-27T18:03:41.7038567Z Description  : Copy files to Azure blob or VM(s)
2018-11-27T18:03:41.7038647Z Version      : 2.0.15
2018-11-27T18:03:41.7038738Z Author       : Microsoft Corporation
2018-11-27T18:03:41.7038823Z Help         : [More Information](https://aka.ms/azurefilecopyreadme)
2018-11-27T18:03:41.7038939Z ==============================================================================
2018-11-27T18:03:41.7244544Z ##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
2018-11-27T18:03:41.7258675Z ##[section]Finishing: AzureBlob File Copy
johnwc commented 1 year ago

@starkmsu @onetocny @DmitriiBobreshev think anyone can possibly look into this issue from 2018?

kolosovpetro commented 1 year ago

AzCopy may be used directly from AzureCLI@2 as follows

- task: AzureCLI@2
  displayName: 'AzCopy via Azure CLI'
  inputs:
    azureSubscription: 'AzCopyARM'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      $Date = (Get-Date).AddDays(1).ToString('yyyy-MM-dd')
      $key = $( az storage account keys list --resource-group $(rgName) --account-name $(storageAccount) --query [0].value -o tsv )
      $sas = $( az storage container generate-sas --name $(container) --expiry $Date --permissions "racwdli" --account-name $(storageAccount) --account-key "$key" )
      azcopy copy "./seed_images/*" "https://$(storageAccount).blob.core.windows.net/$(container)/from_az_cli?$(SAS)" --recursive=true

See docs:

basdakkenhorst commented 1 year ago

The following seems to work to "copy" text files (or shell scripts, or ....) to a VM from a pipeline, using a pipeline variable:

Disclaimer: I must admit I scared myself by doing this. Far from clean, but at least it seems to work.

jobs:
- job: TextCopyToVM

  steps: 

  - bash: |
      filePath="$(< path/to/some/text/file/from/git/repo.txt)"
      #
      # Replace \n with %0D%0A, so a multiline pipeline variable is possible
      #
      escapedFile=$(echo "$filePath" | sed ':a;N;$!ba;s/\n/%0D%0A/g')
      echo "##vso[task.setvariable variable=localFileEscaped]$escapedFile"

  - task: AzureCLI@2
    displayName: 'Echo var into file'
    inputs:
      azureSubscription: '<Azure Subscription Name>'
      scriptType: 'bash'
      scriptLocation: 'inlineScript'
      inlineScript: |
        echo "localFileEscaped: $(localFileEscaped)"
        COPY_FILE="$(az vm run-command invoke -g <RESOURCE GROUP> -n <VM NAME> --command-id RunShellScript --scripts 'echo "$(localFileEscaped)" > /some/path/to/file/on/vm.txt')"
bcichonski commented 11 months ago

Since this is still a thing with a recent comment and since I had same problem landing eventually here, I would like to tell that

  1. @kolosovpetro solution worked great
  2. but only when I changed network access rules with az storage account update --name $ACCOUNT --resource-group $RESOURCE_GROUP --default-action Allow

otherwise the error you get is just telling you that you have authentication problem. This might save you a lot of hours thinking about your life choices while you are trying to resolve this.

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

StefanSchoof commented 5 months ago

We still want this feature ;)

musekmkr commented 5 months ago

+1

ksks200 commented 1 month ago

Yes we want this feature.

rmmason commented 3 weeks ago

Also interested in seeing this given some love from Microsoft.