Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Created December 23, 2017 10:54
Show Gist options
  • Save vegaasen/b97ef15aca0a84361c6a1674fd56e0c8 to your computer and use it in GitHub Desktop.
Save vegaasen/b97ef15aca0a84361c6a1674fd56e0c8 to your computer and use it in GitHub Desktop.
Documentation generation that uses Scroll Pdf plugin for confluence. Used in Octopus.
#!/usr/bin/env bash
# Triggers, verifies and downloads the User Guide from ITDoc
# Requires the following variables to be defined:
# jobUsername, jobPassword
# ^----- these relies on variable credentials being supplied by Jenkins variable (See "Bindings" => Username/Password) components
#
# @author vegaasen
# @since 13.12.2017
# @version 13.12.2017@IAM-1231
userGuideRequestTicket="user-guide-ticket.json";
userGuideRequestStatus="user-guide-status.json";
userGuideFileName="whatever.pdf";
status="ungenerated";
requestId="";
downloadUrl="";
jobUsername=${credentials%:*};
jobPassword=${credentials#*:};
echo "Triggering documentation";
curl -u "${jobUsername}":"${jobPassword}" -k -X POST -H 'Content-Type: application/json;charset=utf-8' -H 'Accept: application/json, text/plain, */*' -d '{"pageId":"14549275","pageSet":"current","pageOptions":{},"templateId":"45864a12-0b34-4ae5-8964-ff2b586bdd93","locale":"en-GB","debugMode":false,"properties":{"labels":{"includeContentWithLabels":[],"excludeContentWithLabels":[],"indexTerms":["enableLabelsAsIndexTerms"]},"content":{"headings":["enableNumberedHeadings"],"layout":["enablePageLayouts"],"links":["enableExternalLinks"]},"macros":{"macros":["showTocOutput","showChildrenOutput","enableGalleryListMode"]},"title":{"figure":"after","table":"after"},"printOptions":{"optimization":[]},"metadata":{"title":"KDA","author":"someUser@JENKINS","subject":"User Guide","keywords":""},"locale":{"defaultLocale":"en"}}}' "https://our.confluence.local/plugins/servlet/scroll-pdf/api/exports" > ${userGuideRequestTicket};
echo "Saved to ${userGuideRequestTicket}";
echo "Waiting until job is ready for download...";
requestId=`cat ${userGuideRequestTicket} | sed -n 's/.*exportJobId\":\"\(.*\)\"}/\1/p'`;
echo "Using ${requestId} to contact Confluence";
if [ ! -z "${requestId}" ]; then
while [ "$status" != "complete" ]; do
echo "Current status ${status}. Verifying if this is equal to {complete}";
curl -u "${jobUsername}":"${jobPassword}" -k -X GET "https://our.confluence.local/plugins/servlet/scroll-pdf/api/exports/${requestId}/status" > ${userGuideRequestStatus};
status=`cat ${userGuideRequestStatus} | sed -n 's/.*name\":\"\(.*\)\",.*/\1/p'`;
sleep 2;
done
downloadUrl=`cat ${userGuideRequestStatus} | sed -n 's/.*downloadUrl\":\"\(.*\)\".*/\1/p'`;
echo "The document is now generated. Trying to download the file. Should be located at ${downloadUrl}";
curl -o "${userGuideFileName}" -u "${jobUsername}":"${jobPassword}" -k -X GET "${downloadUrl}";
else
echo "Wups. No requestId generated. Authentication problems?";
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment