Jenkins

如何在 Jenkins 中發布 Confluence(Cloud) 頁面

  • February 8, 2019

我想使用 Jenkins 管道將網頁發佈到 Confluence(Cloud)。我使用了 Jenkins Confluence 外掛,它不起作用。當我在全域配置中設置我的融合頁面 url(https://yourDomain.atlassian.net/wiki/)和使用者名和密碼時,它一直說不正確的密碼和使用者名 util 它達到了最大嘗試次數。之後我無法登錄,除非我聯繫我不認識的管理員使用者。

我通過使用 Confluence REST API 解決了這個問題。

請參閱以下 REST API 範例:

$$ a link $$https://developer.atlassian.com/cloud/confluence/rest-api-examples/ 設置全域憑證:您的使用者名和密碼作為使用者名和密碼類型憑證,頁面 id 作為秘密文本憑證。我更新 Confluence 頁面的管道是:

pipeline {
   agent any
   environment {
     CONFLUENCE_PAGE_CREDS = credentials('confluence-creds')
     PAGE_ID = credentials('confluence-page-id')
   }
   stages {
       stage('Update Confluence Page') {
           steps {
               sh '''
                   #!/bin/bash
                   curl -u ${CONFLUENCE_PAGE_CREDS} 'https://YOURDOMAIN.atlassian.net/wiki/rest/api/content/'${PAGE_ID}'?expand=version' | python -mjson.tool > version.txt
                   PAGE_VERSION=$(grep -Po '(?<="number": )[0-9]+' version.txt)
                   rm version.txt
                   PAGE_VERSION=$((PAGE_VERSION+1))
                   curl -u ${CONFLUENCE_PAGE_CREDS} 'https://YOURDOMAIN.atlassian.net/wiki/rest/api/content/'${PAGE_ID}'?expand=body.storage' | python -mjson.tool > body.txt
                   more body.txt
                   PAGE_BODY="$(grep -Po '(?<="value": ")[^"]+' body.txt)"
                   rm body.txt
                   TEXT='<p>The content to append</p>'
                   TEXT=$PAGE_BODY$TEXT
                   echo '{"id":"'${PAGE_ID}'","type":"page","title":"NEW PAGE","space":{"key":"TR"},"body":{"storage":{"value":"'$TEXT'","representation":"storage"}},"version":{"number":'$PAGE_VERSION'}}' > update.json
                   curl -u ${CONFLUENCE_PAGE_CREDS} -X PUT -H 'Content-Type: application/json' -d '@update.json' https://YOURDOMAIN.atlassian.net/wiki/rest/api/content/${PAGE_ID} | python -mjson.tool
                   rm update.json
               '''
           }
       }
   }
}

創建 Confluence 頁面:

pipeline {
   agent any
   environment {
     CONFLUENCE_PAGE_CREDS = credentials('confluence-creds')
     PAGE_ID = credentials('confluence-page-id')
   }
   stages {
       stage('Update Confluence Page') {
           steps {
               sh '''
                   #!/bin/bash
                   TEXT='<p>New page</p>'
                   echo '{"type":"page","title":"New page","ancestors":[{"id":"'${PAGE_ID}'"}],"space":{"key":"TR"},"body":{"storage":{"value":"'$TEXT'","representation":"storage"}}}' > update.json
                   curl -u ${CONFLUENCE_PAGE_CREDS} -X POST -H 'Content-Type: application/json' -d '@update.json' https://YOURDOMAIN.atlassian.net/wiki/rest/api/content/ | python -mjson.tool
                   rm update.json
               '''
           }
       }
   }
}

引用自:https://serverfault.com/questions/953013