0

I need to upload documents from Jenkins workspace to confluence via Jenkinsfile.

I followed up this link and started writing the basic code and sure that this will not work. Can anyone please add or comment or suggest me few links.

void Publish_Doc_Confluence(){
    withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'iam_user_jenkins']]) {
      publishConfluence attachArchivedArtifacts: true, pageName: '', replaceAttachments: true, siteName: '', spaceName: ''
    }
}

I am also using curl command to upload the file but in vain--

command-

    stage('Publish to Confluence') {
              steps {
              withCredentials([usernamePassword(credentialsId: 'confluence', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
              sh '''
            curl -D- -u $USERNAME:$PASSWORD -X PUT -H "X-Atlassian-Token: nocheck" -F "file=@code/pydoc/*.html" -F "minorEdit=false" 'https://alm-tuigroup.atlassian.net/wiki/rest/api/content/504955238/child/attachment'
'''
              }}}

And where exactly I will get the details like below in confluence page-

  • pageneme
  • sitename
  • spacename
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
asur
  • 1,759
  • 7
  • 38
  • 81
  • First of all, do you have a [Confluence Cloud/On-Prem](https://www.atlassian.com/software/confluence) installed? – Prav Dec 18 '18 at 22:41
  • In this case, the base URL of the confluence is what's the `sitename`, then any space that already exists under Spaces when you login is your `spacename`. If you go to settings of a space you can find this under Details tab. `pagename` can be anything you want as this should be created when this job try to upload the content. – Prav Dec 18 '18 at 23:01
  • @PraveenP I have confluence Could installed – asur Dec 19 '18 at 13:44
  • @PraveenP I have updated my question.. Could you tell me what would be my site name/spacename/pagename – asur Dec 19 '18 at 19:38
  • Tbh, I'm not sure why you're looking for these when you have the [API docs](https://developer.atlassian.com/cloud/confluence/rest/#api-content-get) proper examples. – Prav Dec 19 '18 at 19:55
  • SiteName=`https://alm-group.atlassian.net`, SpaceName=`PROJECT` and PageName=`PyDoc`. – Prav Dec 19 '18 at 19:58
  • @PraveenP I have seen this link but couldn't find any curl command to upload more than one files to Confluence. – asur Dec 19 '18 at 22:29
  • Check this https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-child-attachment-put Its bit tricky because you need to know the id of the content/page to upload the attachment. If its same for all attachments (i.e. at the same page) then its easy; otherwise you need to get the content first – Prav Dec 19 '18 at 22:36
  • @PraveenP I have updated my code now with new CURL. It is uploading file as a attachment that too a single file. I have bunch if files, there is no option I could see to upload more than one file. – asur Dec 19 '18 at 22:46
  • I don't think you can do that. You need to either upload a zip/tarball or run a loop that upload all the files one by one. `for file in \`ls path/to/directory-files-in\`;do curl ... "$file"; done`. should be something like that. – Prav Dec 22 '18 at 11:50
  • Have you tried multiple -F? I've answered similar question today: https://stackoverflow.com/questions/53860220/curl-upload-multiple-html-files-to-confluence/54090630#54090630 Also curl doesn't support wildcards. – hakamairi Jan 08 '19 at 12:57

0 Answers0