docToolchain / docs-as-co.de

the source of the docs-as-co.de website
11 stars 7 forks source link

try to publish the easy example to confluence #67

Open eitsch opened 2 years ago

eitsch commented 2 years ago

Hi there,

i would like to ask for assistance. It was very easy (and a nice experience, too ❀️ ) to follow the simple Tutorial on https://docs-as-co.de/getstarted --> The Build-Tool Approach --> Gradle.

calling the asciidoctor task (see below) created the test.html file

After having created the test.html file i wanted to publish that to confluence.

I researched the gradle plugin https://plugins.gradle.org/plugin/de.docs-as-co.publishToConfluence ... but i was not able to find out how to configure it. ... I also looked at http://doctoolchain.org/docToolchain/v2.0.x/015_tasks/03_task_publishToConfluence.html#_configuration ... and tried that ... but i am not doing it the right way 😒

Could you/someone maybe answer with a (configured the right way way 🀷 ⁉️ ) gradle task config for my build.gradle file for the following setup: (the part in the task asciidocToConfluence seems to be improvable πŸ˜… )

Thank you in advance, if you maybe be able to help me!

As an alternative: do you know any github repos that show a working setup for "publishing to confluence"? I then could look at that, and maybe repair it myself ✊

asciidoctor {
  //  sourceDir  file('docs/asciidoc')
  //  sources {
  //    include 'toplevel.adoc', 'another.adoc', 'third.adoc'
  //  }
  //  outputDir  file('build/docs/asciidoc')
}

asciidocToConfluence {

    input = [
        [ file: "build/docs/asciidoc/test.html" ],
    ]

    // endpoint of the confluenceAPI (REST) to be used
    api = 'https://confluence.host.url/rest/api/'

    // the key of the confluence space to write to
    spaceKey = '$CONF_SPACE_KEY'

    // variable to determine whether ".sect2" sections shall be split from the current page into subpages
    createSubpages = false

    // the pagePrefix will be a prefix for each page title
    // use this if you only have access to one confluence space but need to store several
    // pages with the same title - a different pagePrefix will make them unique
    pagePrefix = 'Testtest - '

    // username:password of an account which has the right permissions to create and edit
    // confluence pages in the given space.
    // if you want to store it securely, fetch it from some external storage.
    // you might even want to prompt the user for the password like in this example

    credentials = "$user:$password".bytes.encodeBase64().toString()
}
eitsch commented 2 years ago

oh ... if it is possible ... i would like to NOT configure the whole shebang ... so no downloaded fulld docToolchain

if possible i would like to "just" have a rather simple asciidoc to html followed by upload stuff to confluence experience ... can that be created? πŸ˜‡ if yes: how? ... or: where can i take a look at an example? πŸ€“ TYVM!!

rdmueller commented 2 years ago

the problem with the publishToConfluence task is that there is no open confluence instance and there are lots of different ways to connect.

Here is a configuration which I used lately:

confluence.with {
    input = [
            [ file: "build/html5/demo/asciidoc.html" ],
    ]

    // endpoint of the confluenceAPI (REST) to be used
    // verfiy that you got the correct endpoint by browsing to
    // https://[yourServer]/[context]/rest/api/user/current
    // you should get a valid json which describes your current user
    // a working example is https://arc42-template.atlassian.net/wiki/rest/api/user/current
    api = 'https://arc42-template.atlassian.net/wiki/rest/api/'

    //    Additionally, spaceKey, createSubpages, pagePrefix and pageSuffix can be globally defined here. The assignment in the input array has precedence

    // the key of the confluence space to write to
    spaceKey = 'ADOC'

    // the title of the page containing the preamble (everything the first second level heading). Default is 'arc42'
    preambleTitle = ''

    // variable to determine whether ".sect2" sections shall be split from the current page into subpages
    createSubpages = true

    // the pagePrefix will be a prefix for each page title
    // use this if you only have access to one confluence space but need to store several
    // pages with the same title - a different pagePrefix will make them unique
    pagePrefix = ''

    pageSuffix = ''

    /*
    WARNING: It is strongly recommended to store credentials securely instead of commiting plain text values to your git repository!!!
    Tool expects credentials that belong to an account which has the right permissions to to create and edit confluence pages in the given space.
    Credentials can be used in a form of:
     - passed parameters when calling script (-PconfluenceUser=myUsername -PconfluencePass=myPassword) which can be fetched as a secrets on CI/CD or
     - gradle variables set through gradle properties (uses the 'confluenceUser' and 'confluencePass' keys)
    Often, same credentials are used for Jira & Confluence, in which case it is recommended to pass CLI parameters for both entities as
    -Pusername=myUser -Ppassword=myPassword
    */
    credentials = "<user>:<token>".bytes.encodeBase64().toString()
    //optional API-token to be added in case the credentials are needed for user and password exchange.
    // apikey = ""

    // HTML Content that will be included with every page published
    // directly after the TOC. If left empty no additional content will be
    // added
    // extraPageContent = '<ac:structured-macro ac:name="warning"><ac:parameter ac:name="title" /><ac:rich-text-body>This is a generated page, do not edit!</ac:rich-text-body></ac:structured-macro>
    extraPageContent = ''

    // enable or disable attachment uploads for local file references
    enableAttachments = false

    // default attachmentPrefix = attachment - All files to attach will require to be linked inside the document.
    // attachmentPrefix = "attachment"

    // Optional proxy configuration, only used to access Confluence
    // schema supports http and https
    // proxy = [host: 'my.proxy.com', port: 1234, schema: 'http']

    // Optional: specify which Confluence OpenAPI Macro should be used to render OpenAPI definitions
    // possible values: ["confluence-open-api", "open-api", true]. true is the same as "confluence-open-api" for backward compatibility
    // useOpenapiMacro = "confluence-open-api"
}

now, the main question is, what kind of error you get.

Have you tested that your endpoint configuration is correct?

if your config is for example api = 'https://arc42-template.atlassian.net/wiki/rest/api/', then you should get a valid response if you just navigate your browser to https://arc42-template.atlassian.net/wiki/rest/api/user/current.

This is the best check for this setting.

If this works, we can try the next step.

eitsch commented 2 years ago

... just wanted to leave a signal of "thread is not dead yet" so that you know

your level of activity is positively astonishing (meaning: i am sorry to have not followed up yet although i was very happy to find your prompt reply here ... and now happy cadaver day is approaching fast, oh my :) )

i will try to check the api endpoints response, try to better describe what is happening and my next reply will probably make more sense in the context of this issue

rdmueller commented 2 years ago

btw: do you want to publish to a cloud on on premise instance? Both versions are able to handle different Tokens for authentication.

The cloud one needs credentials like shown in my example. The other one needs the token as bearerToken in the config - without user name.

Authentication is always the hardest part for publishToConfluence