2

I'm trying to write from jenkins into confluence, but I am having some issues either getting a particular solution to work (configuration? plugin bugs?), or having issues finding appropriate information to implement.

Sample end result:

  • A Jenkins Job queries Cloudflare API and generates a table of DNS entries to enter into confluence.
  • Confluence tracks changes and provides a history (cloudflare doesn't appear to have any auditing functionality

Potential Solution 1 - Confluence Publisher Plugin

  • I've tried this plugin, but it appears to be extremely old (not updated in 4 years, and developer of plugin hasn't shown any noticeable activity in maybe 3 years).
  • We use Atlassians Cloud Confluence, but attempting to do the global configuration and testing the login triggers a generic "username/password not accepted" error when testing with my own credentials.
  • After a number of attempts, the message has changed to too many attempts, and taking the steps listed does not change the error message (re-logging into the standard web UI)

(the code block below won't show up unless there's something between the list above and the code block... serverfault formatting bug?)

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: com.atlassian.confluence.rpc.AuthenticationFailedException: Attempt to log in user 'redacted@redacted.com' failed. The maximum number of failed login attempts has been reached. Please log into the web application through the web interface to reset the number of failed login attempts.
 faultActor: 
 faultNode: 
 faultDetail: 
    {}com.atlassian.confluence.rpc.AuthenticationFailedException:null
    {http://xml.apache.org/axis/}hostname:redacted.atlassian.net

com.atlassian.confluence.rpc.AuthenticationFailedException: Attempt to log in user 'redacted@redacted.com' failed. The maximum number of failed login attempts has been reached. Please log into the web application through the web interface to reset the number of failed login attempts.

Potential Solution 2 - Publish Jenkins to arbitrary host and use iframe macro from confluence

  • EDIT - I may actually be able to make this solution work. I may be an idiot for thinking something here would pose a challenge.
  • https://ip-ranges.amazonaws.com/ip-ranges.json
  • Finally, I'd still need to hack on a solution to track changes (push to git?)

Potential Solution 3 - I have discovered that I can likely use the REST API directly. The challenge is making sure the curl call is perfectly formatted (json + html content)

Potential Solution N - Have I missed something?

Ryan
  • 65
  • 2
  • 7

1 Answers1

1

I ended up going the REST API route, using jq to parse incoming JSON

First get the page id:

pageID=$(curl -u $Confluence_UserID:$Confluence_Password -X GET \
    "https://redacted.atlassian.net/wiki/rest/api/content?title=$PageTitle&spaceKey=$Space" \
    | jq -r .results[].id \
    )

Then get the version (version number must be provided and incremented or the update call fails!)

pageVersion=$(curl -u $Confluence_UserID:$Confluence_Password \
    "https://redacted.atlassian.net/wiki/rest/api/content/$pageID?expand=version" \
    | jq .version.number \
    )
((pageVersion++))

Earlier in the jenkins job, it generated the HTML for the confluence page into a file in the workspace. Load that for use below

htmlOutput=$(<myHTMLSnippet.txt)

And the final part, sending the page update

curl -u $Confluence_UserID:$Confluence_Password \
    -X PUT -H 'Content-Type: application/json' \
    https://redacted.atlassian.net/wiki/rest/api/content/$pageID \
    --data @- <<END;
{
    "id": "$pageID",
    "type": "page",
    "title": "$PageTitle",
    "space": {
        "key": "$Space"
    },
    "body": {
        "storage": {
            "value": "$htmlOutput",
            "representation": "storage"
        }
    },
    "version": {
        "number": $pageVersion,
        "minorEdit": true
    }
}
END
Ryan
  • 65
  • 2
  • 7