Forum Discussion
LaTex (.tex) pipeline
How can I compile and store the main.pdf file, back in the repository?
Azure DevOps Pipeline (yaml). This is how far I got, without breaking it:
Edited several times:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
sudo apt-get install texlive
# echo Starting pdflatex
pdflatex -interaction=nonstopmode main.tex
# echo Done pdflatex
# Publish the file in question, the pdf
- task: PublishPipelineArtifact@1
inputs:
targetPath: main.pdf
artifact: 'MyArtifact'
publishLocation: 'pipeline'
# This works well. The file is available in pipelines, related, published. Slightly faster than the DownloadBuildArtifact@
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'MyArtifact'
targetPath: '$(Pipeline.Workspace)'
It compiles, publishes the pdf and allows one to download it. Trying to discover how to store it back in the repository every time I sync with the main branch.
Why: searching for a substitute to README.md
https://www.reddit.com/r/azuredevops/comments/zstcxz/project_wikidocumentation/
This is the current solution that is working for me.
- it compiles the LaTex and creates a main.pdf.
- publishes and downloads to the pipeline.
- pushes the main.pdf to the repository (without constantly triggering the master branch. Does not enter in an endless cycle of push and trigger pipeline).
Azure-pipeline.yml:
# specific branch build with batching trigger: batch: true # when a pipeline is running, the system waits until the run is completed branches: include: - master paths: include: - main.tex # attempt to trigger only when the main.tex is edited pool: vmImage: ubuntu-latest steps: - checkout: self persistCredentials: true - bash: | git checkout '$(Build.SourceBranchName)' # This is needed if you want to push later on sudo apt-get install texlive # echo 'Starting pdflatex' pdflatex -interaction=nonstopmode main.tex # echo 'Compile LaTex: Done' # Publish the file in question, the pdf - task: PublishPipelineArtifact@1 inputs: targetPath: main.pdf artifact: 'MyArtifact' publishLocation: 'pipeline' # This works well. The file is available in pipelines, related, published. Slightly faster than the DownloadBuild - task: DownloadPipelineArtifact@2 inputs: buildType: 'current' artifactName: 'MyArtifact' targetPath: '$(Pipeline.Workspace)' # Push the main.pdf to the repository - bash: | # git checkout $(Build.SourceBranchName) git add main.pdf git config --global user.name '$(Build.RequestedFor)' git config --global user.email '$(Build.RequestedForEmail)' git commit -m "Update pdf" git push origin HEAD:master # this one works! #git push origin '$(Build.SourceBranchName)' # error is here!!? #git push origin HEAD:main # doesn't work for azure reps #git push origin HEAD:<$(Build.SourceBranchName)> # doesn't work
usefull links.:
azure rep documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#paths
You need to give permissions to the "build service": https://stackoverflow.com/questions/66470759/set-git-credentials-inside-a-azure-yaml-pipeline
Scripts need access to the token: https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml#allow-scripts-to-access-the-system-token
An issue with "main" and "master" branches. This might be a bug, so I forced the name HEADER:master : https://stackoverflow.com/questions/4181861/message-src-refspec-master-does-not-match-any-when-pushing-commits-in-git
Tip, use the assistant on the right corner to add baked code while editing the yaml in azure.
- ppCopper Contributor
If anyone is looking for a solution with Github, check this one.
Github action.: https://github.com/xu-cheng/latex-actionWith a docker image and gitlab.:
https://hub.docker.com/r/drpsychick/texlive-pdflatex/
- ppCopper Contributor
This is the current solution that is working for me.
- it compiles the LaTex and creates a main.pdf.
- publishes and downloads to the pipeline.
- pushes the main.pdf to the repository (without constantly triggering the master branch. Does not enter in an endless cycle of push and trigger pipeline).
Azure-pipeline.yml:
# specific branch build with batching trigger: batch: true # when a pipeline is running, the system waits until the run is completed branches: include: - master paths: include: - main.tex # attempt to trigger only when the main.tex is edited pool: vmImage: ubuntu-latest steps: - checkout: self persistCredentials: true - bash: | git checkout '$(Build.SourceBranchName)' # This is needed if you want to push later on sudo apt-get install texlive # echo 'Starting pdflatex' pdflatex -interaction=nonstopmode main.tex # echo 'Compile LaTex: Done' # Publish the file in question, the pdf - task: PublishPipelineArtifact@1 inputs: targetPath: main.pdf artifact: 'MyArtifact' publishLocation: 'pipeline' # This works well. The file is available in pipelines, related, published. Slightly faster than the DownloadBuild - task: DownloadPipelineArtifact@2 inputs: buildType: 'current' artifactName: 'MyArtifact' targetPath: '$(Pipeline.Workspace)' # Push the main.pdf to the repository - bash: | # git checkout $(Build.SourceBranchName) git add main.pdf git config --global user.name '$(Build.RequestedFor)' git config --global user.email '$(Build.RequestedForEmail)' git commit -m "Update pdf" git push origin HEAD:master # this one works! #git push origin '$(Build.SourceBranchName)' # error is here!!? #git push origin HEAD:main # doesn't work for azure reps #git push origin HEAD:<$(Build.SourceBranchName)> # doesn't work
usefull links.:
azure rep documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#paths
You need to give permissions to the "build service": https://stackoverflow.com/questions/66470759/set-git-credentials-inside-a-azure-yaml-pipeline
Scripts need access to the token: https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml#allow-scripts-to-access-the-system-token
An issue with "main" and "master" branches. This might be a bug, so I forced the name HEADER:master : https://stackoverflow.com/questions/4181861/message-src-refspec-master-does-not-match-any-when-pushing-commits-in-git
Tip, use the assistant on the right corner to add baked code while editing the yaml in azure.