Unable to upload zip file from Azure pipeline VM to Confluence page
Asked by Saket Singh:

I'm trying to upload a zip file present in the Azure pipeline VM to Confluence page  

#### retrieving the file name {#toc-hId--480793619}

out="$(basename $(Build.ArtifactStagingDirectory)/\*.zip)"

echo $out

#### Upload command {#toc-hId-2006719214}

curl -D- -u 'userid:token'  
-X POST  
-H 'X-Atlassian-Token: nocheck'  
-F 'file=@$(out)'  
'confluence_url/rest/api/content/page_id/child/attachment'

Error curl: (26) Failed to open/read local data from file/application

If I add the file name it's working fine.


Answers:
author: James Richards
body: Hi [@Saket Singh](/t5/user/viewprofilepage/user-id/4779869)

Looking at the error output

```
./prog.sh: line 2: Build.ArtifactStagingDirectory: command not found
./prog.sh: line 4: Build.ArtifactStagingDirectory: command not found
./prog.sh: line 7: Output: command not found
./prog.sh: line 8: /home/vsts/work/1/s: No such file or directory
./prog.sh: line 9: total: command not found
./prog.sh: line 10: -rw-r--r--: command not found
./prog.sh: line 11: 269.zip: command not found
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
./prog.sh: line 16: -X: command not found
./prog.sh: line 17: -H: command not found
./prog.sh: line 18: -F: command not found
./prog.sh: line 21: Output-: command not found
./prog.sh: line 22: syntax error near unexpected token `26'
./prog.sh: line 22: `curl: (26) Failed to open/read local data from file/application'
```

There are errors from line 2 onwards. The issue isn't that the upload isn't working, but pretty much everything isn't working. You have output mixed in with shell commands.

Lines 7\~11 and 21\~23 are causing issues. Also, *confluence_url* isn't working, as that's not a valid URL.

I suggest cleaning up *prog.sh* first and then trying again.

James.


author: James Richards
body: Hi [@Saket Singh](/t5/user/viewprofilepage/user-id/4779869)

I'm looking at this again and I realise now the error you're using $() instead of ${} in the shell commands.

It should be something like this

And replace

* userid
* token
* confluence_url
* page_id

with the correct values.

1. cd ${Build.ArtifactStagingDirectory}
2. temp="$(basename ${Build.ArtifactStagingDirectory}/\*.zip)"
3. 
4. curl -D- -u 'userid:token' \\
5. -X POST \\
6. -H 'X-Atlassian-Token: nocheck' \\
7. -F 'file=@"${Build.ArtifactStagingDirectory}/$temp"' \\
8. '${confluence_url}/rest/api/content/${page_id}/child/attachment'

James.

comments: author: Saket Singh
body: It's working now. Thanks James!


author: Pramodh M
body: Hi [@Saket Singh](/t5/user/viewprofilepage/user-id/4779869)

Make sure the file which is generated has only one zip file content.

Also when the file is referenced in API, can you make sure the file path which is given has an absolute path

Please try the above and let me know

Thanks

comments: author: Saket Singh
body: Hi [@Pramodh M](/t5/user/viewprofilepage/user-id/3691224) ,  

only 1 zip file is getting generated in the directory.  

I've provided the absolute path still getting the same error. Please refer to the below link for the updated command.  

<https://ideone.com/0nZz1O>  

Thanks!


Tags: bash

cloud

confluence-cloud