Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Last active January 23, 2024 15:04
Show Gist options
  • Save sheldonhull/053cb176d5c2847a4e323f01207acb82 to your computer and use it in GitHub Desktop.
Save sheldonhull/053cb176d5c2847a4e323f01207acb82 to your computer and use it in GitHub Desktop.
asciidoc-azure-pipelines.yaml Example of using azure devops yaml pipeline to publish documentation to confluence from a repo. docs-as-code for the win.
name: $(BuildDefinitionName).$(DayOfYear)$(Rev:.r).$(Build.RequestedFor)
trigger:
branches:
include:
- master
pr: none # don't trigger on pr, only when merging to master
pool:
vmImage: 'ubuntu-latest'
variables:
- group: confluence-publisher # Go to Library in Azure taco-ops and create your variables below, so you can easily change if needed in future
# ROOT_CONFLUENCE_URL
# USERNAME
# PASSWORD
- name: SPACE_KEY
value: taco-ops
- name: ANCESTOR_ID
value: 123456 # ๐Ÿšฉ the parent page you want to put everything under. Anything under this will be ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ purged ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ
# this is the repo to send distributed docs from github repos, so you can seperate the repos from your main run book
- name: GITHUB_ANCESTOR_ID
value: 1234567 # ๐Ÿšฉ the parent page you want to put everything under. Anything under this will be ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ purged ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ๐Ÿšฉ
- name: PUBLISHING_STRATEGY
value: APPEND_TO_ANCESTOR
- name: VERSION_MESSAGE # I'm not using, but could be possible to use gitversion tool or other to tag this stuff with semver automatically. I choose not to do that so it doesn't create more possible noise right now in updates
value: ''
- name: CONSOLIDATED_FOLDER_NAME # This is a folder to copy all the github matched repo doc folders to so you can generate subpages automatically on all of them
value: 'consolidated-documentation'
resources:
repositories:
- repository: taco-ops-runbook
type: github
endpoint: github-taco-ops-connection
name: taco/taco-ops-runbook
- repository: terraform-taco
type: github
endpoint: github-taco-ops-connection
name: taco/terraform-taco
- repository: taco-ops-packer
type: github
endpoint: github-taco-ops-connection
name: taco/taco-ops-packer
# ref: develop
- repository: taco-ops-reports
type: github
endpoint: github-taco-ops-connection
name: taco/taco-ops-reports
stages:
- stage: PublishDocumentation
jobs:
- deployment: taco-ops-runbook
displayName: Publish taco-ops-runbook
timeoutInMinutes: 5
environment: taco-ops
strategy:
runOnce:
deploy:
steps:
- checkout: taco-ops-runbook
clean: false
persistCredentials: true
- checkout: terraform-taco
clean: false
persistCredentials: true
- checkout: taco-ops-packer
clean: false
persistCredentials: true
- checkout: taco-ops-reports
clean: false
persistCredentials: true
# didn't get working due to multiple repos, so disabled, but kept here for reference
# - task: GitVersion@5
# inputs:
# runtime: 'core'
# configFilePath: '$(Build.SourcesDirectory)/taco-ops-runbook/GitVersion.yml'
# fetchDepth: 1 #GITVERSION needs history to calculate property versioning
# https://confluence-publisher.atlassian.net/wiki/spaces/CPD/overview?mode=global
- pwsh: |
Write-Host "Searching for docs folders under `$ENV:PIPELINE_WORKSPACE: $ENV:PIPELINE_WORKSPACE"
$Directories = (Get-ChildItem -Path $ENV:PIPELINE_WORKSPACE -Directory -Filter 'docs' -Recurse | Where-Object FullName -notmatch 'taco-ops-runbook').FullName
Write-Host "--- Directories to Copy ---`n$($Directories | Format-Table -Autosize -Wrap | Out-String)"
Write-Host "๐Ÿ‘Œ Creating folder called $ENV:CONSOLIDATED_FOLDER_NAME in current path to simplify multi-repo doc publishing"
$consolidatedfolder = (New-Item -Path $ENV:CONSOLIDATED_FOLDER_NAME -ItemType Directory -Force).FullName
$Directories | ForEach-Object {
$dir = $_
Write-Host "๐Ÿ‘Œ Copying contents of $dir into $consolidatedfolder"
Copy-Item $dir -Recurse -Destination $consolidatedfolder -Verbose -Force
}
Write-Host "๐ŸŽ‰ done copying contents, here is a report of the files in destination for your ease of debugging"
Write-Debug "$(Get-ChildItem $consolidatedfolder -Recurse | Format-Table -Autosize -Wrap | Out-String)"
displayName: Copy GitHub docs to central folder to simplify adding repos for publishing
env:
CONSOLIDATED_FOLDER_NAME: $(CONSOLIDATED_FOLDER_NAME)
- bash: |
echo "๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ"
echo "Running confluence publisher ๐ŸŒฎ"
echo "๐Ÿ“ƒ Publishing taco-ops-runbook repo contents"
docker run --rm -v $BUILD_SOURCESDIRECTORY/taco-ops-runbook/docs:/var/asciidoc-root-folder -e ROOT_CONFLUENCE_URL=$ROOT_CONFLUENCE_URL \
-e SKIP_SSL_VERIFICATION=false \
-e USERNAME=$USERNAME \
-e PASSWORD=$PASSWORD \
-e SPACE_KEY=$SPACE_KEY \
-e ANCESTOR_ID=$ANCESTOR_ID \
-e PUBLISHING_STRATEGY=$PUBLISHING_STRATEGY \
confluencepublisher/confluence-publisher:0.0.0-SNAPSHOT
echo "๐Ÿ“ƒ Publishing $CONSOLIDATED_FOLDER_NAME repo contents"
docker run --rm -v $BUILD_SOURCESDIRECTORY/$CONSOLIDATED_FOLDER_NAME/docs:/var/asciidoc-root-folder -e ROOT_CONFLUENCE_URL=$ROOT_CONFLUENCE_URL \
-e SKIP_SSL_VERIFICATION=false \
-e USERNAME=$USERNAME \
-e PASSWORD=$PASSWORD \
-e SPACE_KEY=$SPACE_KEY \
-e ANCESTOR_ID=$GITHUB_ANCESTOR_ID \
-e PUBLISHING_STRATEGY=$PUBLISHING_STRATEGY \
confluencepublisher/confluence-publisher:0.0.0-SNAPSHOT
echo "documentation should be published"
echo "๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ๐ŸŒฎ"
workingDirectory: $(Build.SourcesDirectory)
displayName: 'run confluence publisher'
name: confluencepublisher
env:
ROOT_CONFLUENCE_URL: $(ROOT_CONFLUENCE_URL)
USERNAME: $(USERNAME)
PASSWORD: $(PASSWORD)
SPACE_KEY: $(SPACE_KEY)
ANCESTOR_ID: $(ANCESTOR_ID)
PUBLISHING_STRATEGY: $(PUBLISHING_STRATEGY)
VERSION_MESSAGE: $(VERSION_MESSAGE)
CONSOLIDATED_FOLDER_NAME: $(CONSOLIDATED_FOLDER_NAME)
timeoutInMinutes: 5
# - task: printAllVariables@1
# condition: always()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment