docker - 是否可以在 Azure DevOps Pipeline 中运行 GitHub Workflow Actions?

标签 docker azure-devops yaml azure-pipelines github-actions

据我了解,GitHub 操作也可以由 (Linux) Docker 镜像执行来执行特定任务。

例如这个 GitHub 操作 Azure/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9aaadb8adb0baf4aebcbbf4b8a9a9aaf4bdbca9b5b6a099afe9f7e9f7e8f4a9abbcafb0bcae" rel="noreferrer noopener nofollow">[email protected]</a>使用 Docker 镜像 mcr.microsoft.com/appsvc/staticappsclient:stable将项目部署到 Azure 静态 Web 应用程序。

有没有办法在 YAML DevOps 管道中调用/执行/运行此 Docker 镜像?

最佳答案

Container jobs Azure DevOps 管道中的内容可能就是您正在寻找的。

当您在管道中指定容器时,代理将首先获取并启动该容器。然后,作业的每一步都将在容器内运行。所以你可以将Docker镜像设置为容器。请参阅下面的示例:

run a job在容器中:

pool:
  vmImage: 'ubuntu-18.04'

container: mcr.microsoft.com/appsvc/staticappsclient:stable

steps:
- script: printenv

运行certain task在容器中:

resources:
  containers:
  - container: staticappsclient
    image: mcr.microsoft.com/appsvc/staticappsclient:stable

steps:
- task: SampleTask@1
  target: host
- task: AnotherTask@1
  target: staticappsclient  # this task will run in the container

更新:

在未预安装 sudo 的容器内运行 sudo 命令。您可以查看以下步骤:

1、通过定义--name来命名容器选项 options: "--name ci-container -v /usr/bin/docker:/tmp/docker:ro" 中的参数

2, 在 yaml 管道顶部添加脚本任务来安装 sudo

- script: |
      /tmp/docker exec -t -u 0 ci-container \
      sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo"

3、在以下脚本任务中运行脚本来安装 dotnet 3.1:请参阅下面的完整 yaml 示例:

resources:
  containers:
  - container: staticappsclient
    image: mcr.microsoft.com/appsvc/staticappsclient:stable
    options: "--name ci-container -v /usr/bin/docker:/tmp/docker:ro"

container: staticappsclient

steps:
- script: |
      /tmp/docker exec -t -u 0 ci-container \
      sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo"
   
  
- script: |
    
    wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
    
    sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
    wget https://packages.microsoft.com/config/debian/9/prod.list
    sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
    sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
    sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
    
    sudo apt-get install -y apt-transport-https && \
    sudo apt-get update && \
    sudo apt-get install -y dotnet-sdk-3.1

参见this thread了解更多信息。

关于docker - 是否可以在 Azure DevOps Pipeline 中运行 GitHub Workflow Actions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66289675/

相关文章:

docker - 如何在Lando Appserver中的/etc/hosts中添加条目?

docker - Docker-compose应该运行一次我的入口点脚本然后退出两次

wcf - Jenkins 与 Visual Studio Online 集成认证

amazon-web-services - 我应该在我的存储库中包含我的 .aws-sam 文件吗?

docker - 当我 `ddev start`时,我得到 “Get https://registry-1.docker.io/v2/drud/ddev-ssh-agent/manifests/v1.6.0: unauthorized: incorrect username or password”

windows - 如何在 osx 上运行 docker windows 容器?

git - 创建 git repo 并将本地目录推送到新初始化的 Azure Repos

azure-devops - 我应该在构建或发布管道的什么地方运行测试?

ruby 脚本 : undefined method `symbolize_keys' error loading YAML files

python-3.x - 加载 yaml 列表作为字典