TeX Live冻结时,如何在Azure DevOps中实现Sphinx自动文档生成?
问题
我通过Sphinx、Makefile及Git追踪的.rst文件,用Azure Pipeline自动更新仓库中的PDF文档。为了让用户本地运行Makefile时能用相同命令,我配置了Windows环境的azure_pipeline.yml,代码如下:
# Trigger the pipeline pull requests in master (commits are not allowed in master) # In Azure devops this should be added using a 'build validation policy'. This trigger can not be done in this yaml trigger: - master pool: vmImage: 'windows-latest' # Define here which python version will be used strategy: matrix: Python39: python.version: '3.9' # Use python version defined before steps: - task: UsePythonVersion@0 inputs: versionSpec: '$(python.version)' displayName: 'Use Python $(python.version)' # Install sphinx dependencies, use pep517 to get sklearn to work - script: | python -m pip install -r sphinx_requirements.txt displayName: 'Install sphinx dependencies' # Install make to create the sphinx documentation, this way the pipeline can be used similar as locally using the 'make pdf' call in build.cmd - script: | choco feature enable -n allowGlobalConfirmation echo Install Make choco install -y make refreshenv workingDirectory: docs/ displayName: 'Install make' # Install texlive, which is a free distribution of the TeX typesetting system # Install the basic version with all the packages we used in the documentation that is not already included in the basic scheme - script: | choco install -y texlive --params="'/InstallationPath:C:\ProgramData\chocolatey\lib\texlive /scheme:basic /extraPackages:cmap,fncychap,transparent,eso-pic,lipsum,footnotebackref,setspace,datetime,etoolbox,xcolor,sectsty,enumitem,epigraph,float,wrapfig,capt-of,framed,upquote,needspace,parskip,tabulary,varwidth,fancyvrb,titlesec,fmtcount,xkeyval,nextpage'" refreshenv displayName: 'Install texlive' # Create the sphinx documentation with miktex that is just downloaded # Note, that if we are using miktex instead of texlive, we need to set the PATH, just to be sure we will always set it, if we are using texlive, it will just continue - script: | echo Create pdf make pdf workingDirectory: docs/ displayName: 'Create sphinx documentation' # Copy pdf file from - task: CopyFiles@2 displayName: 'Copy pdf file' inputs: SourceFolder: '$(Pipeline.Workspace)' Contents: '**/Palantir.pdf' TargetFolder: '$(Build.ArtifactStagingDirectory)' flattenFolders: true # Publish file to a build artifact - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: pdf' inputs: ArtifactName: Documentation with release notes
该配置此前运行正常,但现在在「Install texlive」步骤中出现错误:
ERROR: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: TeX Live 2022 is frozen texlive may be able to be automatically uninstalled.
我尝试替换为MikTex但未成功,请问如何修改配置恢复Azure Pipeline正常运行?
解决方案
方法1:指定TeX Live的具体可用版本
TeX Live每年会更新大版本,旧版本会被「冻结」(停止维护和提供安装源),导致Chocolatey无法拉取安装包。可以指定安装当前最新的可用版本,比如2024版:
修改「Install texlive」步骤的脚本,添加版本号参数:
choco install -y texlive --version=2024.0417 --params="'/InstallationPath:C:\ProgramData\chocolatey\lib\texlive /scheme:basic /extraPackages:cmap,fncychap,transparent,eso-pic,lipsum,footnotebackref,setspace,datetime,etoolbox,xcolor,sectsty,enumitem,epigraph,float,wrapfig,capt-of,framed,upquote,needspace,parskip,tabulary,varwidth,fancyvrb,titlesec,fmtcount,xkeyval,nextpage'" refreshenv
注意:版本号需要对应Chocolatey上texlive包的最新可用版本,可通过包的官方页面确认。
方法2:使用Azure Agent预装的TeX Live环境
部分Azure Windows虚拟机镜像(如windows-2022)已经预装了TeX Live,可跳过手动安装步骤,直接检查并补充缺失的包:
- 删除原有的「Install texlive」步骤
- 添加检查并安装缺失包的脚本:
# 检查TeX Live是否存在 tlmgr --version if ($LASTEXITCODE -ne 0) { Write-Error "TeX Live not found on the agent" exit 1 } # 安装所需的额外TeX包 tlmgr install cmap fncychap transparent eso-pic lipsum footnotebackref setspace datetime etoolbox xcolor sectsty enumitem epigraph float wrapfig capt-of framed upquote needspace parskip tabulary varwidth fancyvrb titlesec fmtcount xkeyval nextpage
方法3:改用TeX Live官方安装脚本
绕过Chocolatey,直接使用官方安装脚本避免版本冻结问题:
替换原「Install texlive」步骤为以下脚本:
# 下载官方安装器 Invoke-WebRequest -Uri "https://mirror.ctan.org/systems/texlive/tlnet/install-tl-windows.exe" -OutFile "install-tl-windows.exe" # 静默安装基础方案和所需包 .\install-tl-windows.exe --no-gui --scheme=basic --packages=cmap,fncychap,transparent,eso-pic,lipsum,footnotebackref,setspace,datetime,etoolbox,xcolor,sectsty,enumitem,epigraph,float,wrapfig,capt-of,framed,upquote,needspace,parskip,tabulary,varwidth,fancyvrb,titlesec,fmtcount,xkeyval,nextpage --portable # 将TeX Live添加到系统PATH $env:Path += ";$pwd\texlive\2024\bin\win32" refreshenv
注意:脚本中的2024需要根据当前最新TeX Live版本调整。
内容的提问来源于stack exchange,提问作者Harmen Dijkstra
相关产品推荐
相关产品推荐

