如何在jenkins confluence插件的汇合页面中包含一个宏?

时间:2017-05-24 20:26:21

标签: git macros jenkins-plugins confluence

我正在使用Jenkins中的confluence插件(版本1.642.4)将构建结果发布到Confluence(6.0.7)

我正在使用jenkins插件" Confluence Publisher 1.8"。

Jenkins构建作业中的脚本会针对某些类型的注释解析一些Git分支。从该日志中,它创建了一个发布到Confluence的文本文件(CHANGELOG-jenkins.md)。

为了以友好的方式显示文本,我使用了Confluence Markdown宏。 result for the page I create 我添加宏,并添加一个标记文本{jenkins-marker:Release_Notes_Generator_Confluence}。 然后,用于汇合的jenkins插件可以在Markdown宏内写入并正确呈现文本。

但是,我需要jenkins创建一个新的confluence页面(每个构建),所以我需要一种方法来自动化宏插入和标记

jenkins插件已经创建了一个页面,如果它不存在的话。所以我需要能够在创建新页面后将其添加到新页面。然后我还需要将令牌文本添加到宏中。

到目前为止,我还没有找到任何方法来做到这一点。似乎宏"有"用手插入

https://confluence.atlassian.com/conf53/working-with-macros-411108564.html

1 个答案:

答案 0 :(得分:0)

如果有人有兴趣,我最终会找到一种替代方案(从长远来看可能是更好的解决方案)

我使用confluence的REST API将降价宏添加到页面中。 我不是t able to find any doc on JSON needed to add it, but luckily, it非常简单的宏,所以发现必需的字段并不困难。这是最低要求。

<ac:structured-macro ac:name=\"markdown\">
    <ac:plain-text-body><![CDATA[<b>This is my code</b>]]></ac:plain-text-body>
</ac:structured-macro> 

请求网址和正文

https://<confluence_url>:443/rest/api/content/12944217


{
    "id": "12944217",
    "type": "page",
    "status": "current",
    "title": "Release Notes From Jenkins",
    "space": {
        "key": "THEKEY",
        "metadata": {}
    },
        "version": {
        "number": 51,
        "minorEdit": false,
        "hidden": false
    },
    "ancestors": [],
    "operations": [],
    "body": {
        "storage": {
            "value":"<p></ac:structured-macro></p><p><ac:structured-macro ac:name=\"markdown\"><ac:plain-text-body><![CDATA[<b>jenkins-marker:Release_Notes_Generator_Confluence</b>]]></ac:plain-text-body></ac:structured-macro></p>",
        "representation": "storage"
        }
},
"metadata": {}

}