We can use AsciiDoc to write technical documentation. However, confluence is a popular wiki to keep the documentation related to software projects. In this blog let's look at how to publish AsciiDoc documentation in a repo to Confluence via Azure DevOps pipelines.
There are few useful extensions in VS code that you can use for ascii docs.
- AsciiDoc - Visual Studio Marketplace
- UMLet - Visual Studio Marketplace
- Markdown Kroki - Visual Studio Marketplace
First let's create some sample Ascii docs. See example below.
Architecture.adoc the main document containing other docs.
config.adoc config settings.
01_introduction.adoc Intro document.
02_system_overview.adoc Overview documentation. Note here we have reffered to a diagram.
demodiagram.uxf digram is created with umllet.
Let's create a placeholder page in confluence for the documents to be published. My spcae here is having Id DP01. And I have a page created and the Id of it is 2785281. We have to create a page at root level off the space to avoid other pages from getting overwiitten or deleted. Note that there are other docs added manually in the spcace and they should not be overwritten when we run the pipeline.
Then we have to create an API key that needs to be used for updating the docs via pipeline. You can find conflunece documentation here on how to create an API key.
Create two variables in Azure DevOps variable group for the user name and password (the API key we generated in confluence) as shown below.
Then lets create a docker file which will use confluencepublisher/confluence-publisher and install umllet in it as our docs use umlet digrams.
FROM confluencepublisher/confluence-publisher:0.23.0 RUN apk add --no-cache curl ARG umlet_version="15.1" # The umlet zip contains a camelcase directory :-| ENV UMLET_HOME="${UMLET_HOME:-/usr/local/Umlet}" # The umlet extension try to find 'umlet' in PATH and need the 'umlet.jar' in same directory :-| ENV PATH="${UMLET_HOME:-/usr/local/Umlet}:${PATH}" ENV UMLET_JAVA_OPTS="-Djava.awt.headless=true" # Umlet download URL uses inconsistent version formats :-| RUN curl -S -s -o ${TMPDIR}/umlet.zip https://www.umlet.com/download/umlet_${umlet_version//./_}/umlet-standalone-${umlet_version}.zip \ && unzip -d /usr/local ${TMPDIR}/umlet.zip "*.jar" "*.sh"\ && rm -f ${TMPDIR}/umlet.zip \ && ln -snf "${UMLET_HOME}/umlet.sh" "${UMLET_HOME}/umlet"
Then we can define a pipeline job as shown below to publish the documentation. Note that we have used the correct confluence Url, space key and the page id (ANCESTOR_ID). We have use publishing strategy as REPLACE_ANCESTOR and that will replace the docs. The other option to use is APPEND_TO_ANCESTOR.
Pipeline job (pipelines\templates\jobs\publish_docs.yml)
jobs: - job: publish_docs workspace: clean: all displayName: 'Publish Docs' pool: vmImage: ubuntu-22.04 steps: - checkout: self fetchDepth: 1 clean: true persistCredentials: true - task: Bash@3 displayName: 'Publish architecture docs' inputs: workingDirectory: '$(System.DefaultWorkingDirectory)' targetType: 'inline' script: | cd pipelines/dockerfiles; docker pull confluencepublisher/confluence-publisher:0.23.0; docker build --no-cache -t chconfpub:dev --progress=plain -f confluence_publisher.Dockerfile .; docker image ls; docker run --rm -v $(System.DefaultWorkingDirectory)/docs/architecture:/var/asciidoc-root-folder \ -e ROOT_CONFLUENCE_URL=https://chamindac.atlassian.net/wiki \ -e SKIP_SSL_VERIFICATION=false \ -e USERNAME=$(confluence_username) \ -e PASSWORD=$(confluence_password) \ -e SPACE_KEY=DP01 \ -e ANCESTOR_ID=2785281 \ -e PUBLISHING_STRATEGY=REPLACE_ANCESTOR \ -e ORPHAN_REMOVAL_STRATEGY=REMOVE_ORPHANS \ chconfpub:dev docker image rm -f chconfpub:dev; docker image rm -f confluencepublisher/confluence-publisher:0.23.0; docker image ls;
Pipeline (pipelines\publish_docs.yml)
Once the pipline is executed as below, it shows that docs are published.
Confluence page is now updated with the documentation from the repo. We can see the digram is also added to the page.
If we do a modification to the docs as shwon below.
A pipeline is triggered automatically and docs will be updated as shown below.
No comments:
Post a Comment