0

I would like to attached the pdf file to jira from teamcity, how to attached pdf file with prefix e.g. finalExecution202005.pdf ? (here prefix 'finalExecution' is always fixed)

working command: i.e. curl -D- -u %env.JIRAUSER%:%env.JIRAPWD% -X POST -H "X-Atlassian-Token: no-check" -F "file=@finalExecution202005.pdf" http://myhost/rest/api/2/issue/%env.JIRAID%/attachments

after every run filename change so would like to search it through prefix

not working command: i.e. curl -D- -u %env.JIRAUSER%:%env.JIRAPWD% -X POST -H "X-Atlassian-Token: no-check" -F "file=@finalExecution*.pdf" http://myhost/rest/api/2/issue/%env.JIRAID%/attachments

here either i have to used wildcards in filename, but not sure how it work ? or some logic which first search exact filename & then replace that name into url cmd

additional info i am running all my steps on windows agent

jayrajkharat
  • 41
  • 1
  • 6
  • 1
    then what's the problem if this command works? – daggett Apr 12 '20 at 20:46
  • @daggett.. yes above command work from teamcity bcz here I have specified the exact file name. However after every run my file name change .. so the reason want search file with prefix & then use it for upload – jayrajkharat Apr 13 '20 at 04:10

2 Answers2

0

The solution you are seeking for is neither Jira related, nor cURL related. You just need to tell Windows to expand wildcards in your command. This is not possible on Windows (not a problem on Linux).

You can workaround it by using FOR loop and iterating over files in a directory, then storing the last found file (as /OD is used in DIR command) into a variable.

You will need more commands to achieve this. Either write multiple commands (if TeamCity allows it) or prepare your own batch file including multiple commands:

FOR /F "usebackq delims=" %%f IN (`DIR /B /OD finalExecution*.pdf`) DO SET MY_FILE=%%f
curl -D- -u %env.JIRAUSER%:%env.JIRAPWD% -X POST -H "X-Atlassian-Token: no-check" -F "file=%MY_FILE%"

Note, use double percentage sign (%%f) in DOS batch file or single sign (%f) if you run it on commandline within TeamCity.

For answers on this topic:

EDIT: You can run the commands above on a single line this way:

F "usebackq delims=" %f IN (`DIR /B /OD finalExecution*.pdf`) DO SET MY_FILE=%f & curl -D- -u %env.JIRAUSER%:%env.JIRAPWD% -X POST -H "X-Atlassian-Token: no-check" -F "file=%MY_FILE%"

Please notes that the %%f variable has changed to %f as it's not inside the batch file.

CraZ
  • 1,669
  • 15
  • 24
  • If we used batch file then error i.e. curl command is not recognised as an internal or external. & If we put it on teamcity step then teamcity creating new varaible i.e. My_file with empty value (it's not allowing me to run job unless it has somevalue ) – jayrajkharat Apr 20 '20 at 05:09
  • Actually, you can put the commands on a single line using the `&` sign. I've updated my answer above. – CraZ Apr 20 '20 at 07:49
0

solutions as teamcity step : sh -c "FILENAME=$(la final*); curl -D -k -u %env.jira_username%:%env.jira_password% -X post -H \"X-Atlassian-Token: no-check\" -F \"file=@$FILENAME\" %env.JIRA_ENDPOINT%/rest/api/2/issue/%env.JIRA_TEST_EXECUTION_KEY%/attachments"

jayrajkharat
  • 41
  • 1
  • 6
  • This looks more like a Linux command, would it work on your Windows agent? – CraZ Apr 20 '20 at 07:52
  • If you have Linux support installed in Windows (e.g. cygwin, mingw64), then you should specify it in OP to simplify answers and save time to answerers. The easiest answer would be then `curl -D- -u %env.JIRAUSER%:%env.JIRAPWD% -X POST -H "X-Atlassian-Token: no-check" -F "file=@\`ls finalExecution*.pdf\`"` – CraZ Apr 21 '20 at 11:37