当前操作系统无法运行此任务

时间:2019-09-12 15:24:11

标签: azure-devops terraform terraform-provider-azure

从Azure DevOps管道中,使用在docker上运行的自托管linux构建代理,我在terraform计划中得到以下错误。我尝试了很多事情,甚至从构建代理的bash shell运行步骤:效果很好。

您有什么建议吗?

2019-09-12T13:55:21.8133489Z ##[debug]Evaluating condition for step: 'Terraform plan'
2019-09-12T13:55:21.8134075Z ##[debug]Evaluating: succeeded()
2019-09-12T13:55:21.8134246Z ##[debug]Evaluating succeeded:
2019-09-12T13:55:21.8134443Z ##[debug]=> True
2019-09-12T13:55:21.8134723Z ##[debug]Result: True
2019-09-12T13:55:21.8134976Z ##[section]Starting: Terraform plan
2019-09-12T13:55:21.8138406Z ==============================================================================
2019-09-12T13:55:21.8138526Z Task         : Run Terraform
2019-09-12T13:55:21.8138605Z Description  : Run a Terraform on the build agent
2019-09-12T13:55:21.8138647Z Version      : 2.4.0
2019-09-12T13:55:21.8138688Z Author       : Peter Groenewegen - Xpirit
2019-09-12T13:55:21.8138772Z Help         : [More Information](https://pgroene.wordpress.com/2016/06/14/getting-started-with-terraform-on-windows-and-azure/)
2019-09-12T13:55:21.8138828Z ==============================================================================
2019-09-12T13:55:21.8347594Z ##[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.
2019-09-12T13:55:21.8361383Z ##[debug]System.Exception: 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.
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
2019-09-12T13:55:21.8365066Z ##[section]Finishing: Terraform plan

管道在“地形计划”中失败。这是yml:

variables:
  env: 'environment'

steps:
- task: petergroenewegen.PeterGroenewegen-Xpirit-Vsts-Release-Terraform.Xpirit-Vsts-Release-Terraform.Terraform@2
  displayName: 'Terraform plan'
  inputs:
    TemplatePath: '$(System.DefaultWorkingDirectory)/_repository/tf'
    Arguments: 'plan -var-file=$(System.DefaultWorkingDirectory)/_repository/tf/$(env)/$(env).tfvars  '
    InstallTerraform: true
    UseAzureSub: true
    ConnectedServiceNameARM: 'deploy-sco'
    ManageState: true
    SpecifyStorageAccount: true
    StorageAccountResourceGroup: 'rg-terraform'
    StorageAccountRM: sta
    StorageContainerName: terraform
    InitArguments: '-backend-config=$(System.DefaultWorkingDirectory)/_repository/tf/$(env)/$(env).beconf'

构建代理是一个docker容器,使用以下dockerfile构建

FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl jq git iputils-ping libcurl3 libunwind8 netcat libssl-dev unzip wget apt-utils apt-transport-https make binutils gcc lsb-release gnupg
RUN wget -P /tmp/download https://releases.hashicorp.com/terraform/0.12.7/terraform_0.12.7_linux_amd64.zip
RUN wget -P /tmp/download -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
RUN unzip /tmp/download/terraform_0.12.7_linux_amd64.zip -d /tmp/download/
RUN mv /tmp/download/terraform /usr/local/bin
RUN chmod a+x /usr/local/bin/terraform
RUN apt-get install /tmp/download/packages-microsoft-prod.deb
RUN apt-get update
RUN apt-get -y install powershell
RUN wget -P /tmp/download -q https://curl.haxx.se/download/curl-7.65.3.tar.gz
RUN cd /tmp/download; tar xzf curl-7.65.3.tar.gz
RUN cd /tmp/download/curl-7.65.3; ./configure --prefix=/opt/curl-7.65.3 --disable-ipv6 --with-ssl; make; make install
RUN mv /usr/bin/curl /tmp; ln -s /opt/curl-7.65.3/bin/curl /usr/bin/curl
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null
RUN AZ_REPO=$(lsb_release -cs); echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list
RUN apt-get update
RUN apt-get install azure-cli
RUN pwsh -c "Install-Module -Name Az -Force"
RUN pwsh -c "Install-Module -Name Azure -Force"

WORKDIR /azp

COPY ./start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]

1 个答案:

答案 0 :(得分:1)

正如您所说,是的,Terraform计划可以兼容,包括linux,windows和MacOS。但是现在,您面临的问题是您正在使用的扩展名和任务,该任务和扩展名和任务Run Terraform仅可以在Windows上安装的代理中执行。您可以查看其文档以了解以下信息:Getting started with Terraform on Windows and Azure

还有另外一个由我们的Microsoft DevLabs和个人开发人员创建的扩展:TerraformTerraform Build & Release Tasks。这两个扩展中的任务都可以在Windows,Linux和macOS中进行编译。

enter image description here

您最好更改为使用这两个扩展中的任务。