如何为Azure管道容器作业构建Windows Docker容器?

时间:2020-06-01 07:05:01

标签: azure azure-devops azure-pipelines

有关将Jenkins迁移到Azure管道的问题:

  1. 我的.net项目构建需要安装VS buildtool 2017,Windows SDK和WDK。如果我使用代理程序池(MS托管VM)来构建项目,代理池中的所需版本的WDK和SDK是否可用(诸如vs2017-win2016之类的托管VM)?

  2. 如果托管代理无法执行此操作,则如何为Azure管道容器作业构建Win容器,这类似于下面的jenkins代理容器,是否有可用的dockefile示例?谢谢?

jenkins Windows代理的Dockerfile:

FROM openjdk:8-jdk-windowsservercore-1809

ARG version

ENV VERSION ${version:-3.39}
ENV JENKINS_HOME="c:/jenkins"
ENV JENKINS_REMOTING_ENTRY_POINT="${JENKINS_HOME}/agent.jar"
ENV JENKINS_REMOTING_URL="https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar"
ENV SHA=AA1525E45DA5D8CFFD40B67B064C86F9F6CE8799A024EDF5D468D0DC2ABD062D
ENV JENKINS_MASTER_HOST="win-tc-docker"
ENV JENKINS_AGENT_ID="NET_00"
ENV JENKINS_AGENT_SECRET="0000000000000000000000000000000000000000000000000000000000000000"
ENV GIT_VERSION 2.25.0
ENV GIT_PATCH_VERSION 1

SHELL ["powershell", "-NoProfile", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]


# Install Jenkins agent
RUN \    
    New-Item -ItemType Directory -Force -Path $env:JENKINS_HOME; \   
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; \        
    Invoke-WebRequest -Uri $env:JENKINS_REMOTING_URL -OutFile $env:JENKINS_REMOTING_ENTRY_POINT -UseBasicParsing -Proxy http://proxy.compaq.com:8080 -ProxyUseDefaultCredentials;   
#   if ((Get-FileHash -Path $env:JENKINS_REMOTING_ENTRY_POINT -Algorithm SHA256).Hash -ne $env:SHA) { throw 'Download hash does not match'}

# Create temp file for installers
RUN New-Item -ItemType Directory -Force -Path c:\temp;

# Install Subversion (x64) 1.13.1.28686
RUN \    
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; \      
    Invoke-WebRequest "https://osdn.net/frs/redir.php?m=xtom_hk"""&"""f=%2Fstorage%2Fg%2Ft%2Fto%2Ftortoisesvn%2F1.13.1%2FApplication%2FTortoiseSVN-1.13.1.28686-x64-svn-1.13.0.msi" -OutFile "c:/temp/TortoiseSVN.msi" -UseBasicParsing -Proxy http://proxy.compaq.com:8080 -ProxyUseDefaultCredentials;  \   
    Start-Process -FilePath "c:/temp/TortoiseSVN.msi" -ArgumentList '/Passive', '/NoRestart' -PassThru | Wait-Process;

# Install Git
RUN \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \
    Invoke-WebRequest $('https://github.com/git-for-windows/git/releases/download/v{0}.windows.{1}/MinGit-{0}-busybox-64-bit.zip' -f $env:GIT_VERSION, $env:GIT_PATCH_VERSION) -OutFile 'mingit.zip' -UseBasicParsing ; \
    Expand-Archive mingit.zip -DestinationPath c:\mingit ; \
    Remove-Item mingit.zip -Force ; \
    setx /M PATH $('c:\mingit\cmd;{0}' -f $env:PATH)

# Install Blend 4 SDK
RUN \
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; \  
    Invoke-WebRequest "https://download.microsoft.com/download/E/0/0/E0032698-8F1F-497D-B7BD-35275E1EB6FC/BlendWPFSDK_en.msi" -OutFile "c:/temp/Blend4SDK.msi" -UseBasicParsing -Proxy http://proxy.compaq.com:8080 -ProxyUseDefaultCredentials; \
    Start-Process -FilePath "c:/temp/Blend4SDK.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process;

# Install Blend 4.5 SDK
COPY ./BlendSdk "c:/temp/BlendSdk"
RUN Start-Process -FilePath "c:/temp/BlendSdk/BlendWPFSDK.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process;

# Install VS 2017 Build Tools
SHELL ["cmd", "/S", "/C" ]
COPY ./BuildTools2017 "c:/temp/BuildTools2017"
RUN C:\temp\BuildTools2017\vs_buildtools_2017.exe --quiet --wait --norestart --nocache --noWeb \
     --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools \
     --add Microsoft.VisualStudio.Workload.VCTools \
     --add Microsoft.Net.Component.3.5.DeveloperTools \
     --add Microsoft.VisualStudio.Component.Windows10SDK.17763
SHELL ["powershell", "-NoProfile", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]

# Install Visual Studio 2012 Premium
COPY ./VS2012Premium "c:/temp/VS2012Premium"
RUN Start-Process -FilePath "c:/temp/VS2012Premium/vs_premium.exe" -ArgumentList '/passive', '/q', '/s', '/norestart', '/noweb', '/full', '/ProductKey HRFXPFH366KTVG9HXXV8QM3F8' -PassThru | Wait-Process;


# Install WDK 10 1703 (Windows 10.0.15063.0)
COPY ./WDK1703 "c:/temp/WDK1703"
RUN Start-Process -FilePath "c:/temp/WDK1703/wdksetup.exe" -ArgumentList '/q', '/norestart' -PassThru | Wait-Process;

# Install WDK 10 1809 (Windows 10.0.17763.1)
COPY ./WDK1809 "c:/temp/WDK1809"
RUN Start-Process -FilePath "c:/temp/WDK1809/wdksetup.exe" -ArgumentList '/q', '/norestart' -PassThru | Wait-Process;

# Delete temp file content
RUN dir c:\temp | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue;

COPY ./scripts "${JENKINS_HOME}/scripts"

#CMD powershell $env:JENKINS_HOME/scripts/startup.ps1
ENTRYPOINT ["powershell.exe", "-f", "c:/jenkins/scripts/jenkins-agent.ps1"]

1 个答案:

答案 0 :(得分:1)

所需版本的WDK和SDK在代理池中(托管虚拟机,如vs2017-win2016)可用吗?

默认情况下,Hosted Agent上安装了一些特定版本的SDK和WDK,您可以检查它们的版本是否满足您的要求:

virtual-environments for Hosted Agent vs2017-win2016

enter image description here

另一方面,您也可以创建私有代理以将这些组件安装在私有代理中。

是否有可用的dockefile示例?谢谢吗?

您可以创建一个容器并将该组件安装在该容器中。您可以查看此文档以了解更多详细信息:

Install Build Tools into a container

希望这会有所帮助。