Need a way to grab maven built war file

I need help to try and grab a war file that was built in a run section of github actions yml file? Is their a way to put that war file into a curl command file path?

1 Like

You’ll probably need to upload the file as an artifact and then download it where you want to have it, see: Storing workflow data as artifacts - GitHub Docs

Do you know how to reference the file you downloaded like for example ${{}} something like this?

I’m not sure what you mean. Could you provide the steps you’re trying to use?

I first upload the file with the specific file path then I download the file, then I want to use a curl command to grab that file using a varaible

  • name: ‘Upload Artifact’
    uses: actions/upload-artifact@v2
    name: my-artifact
    path: PATH TO FILE
    retention-days: 5

  • name: Download a single artifact
    id: download
    uses: actions/download-artifact@v2
    name: my-artifact`

  • name: Grab File
    run: |
    # curl command here

actions/download-artifact already puts the file(s) into the workspace (on the Actions runner), so there’s no need for an additional curl command. The download-path output should tell you where in the files are in the workspace.

If you want to download the artifact from somewhere else (say, on your own server) you can look at the Actions REST API documentation to figure out how to find and download artifacts.

Sorry, I should’ve been more specific in my question, I want to try and push that downloaded file (which is a war file) to a remote repository by using a curl command. I built the war using a maven install and I can’t push it to this remote repository by referencing the installed location (target folder) it gives me a permission denied, so I wanted to try and download the war file and then reference where it’s downloaded and push it to that remote repository using the curl command

What exactly do you mean by pushing to a remote repository? As in, creating and pushing a Git commit?

What exactly gives you that error?

remote repository I mean a cloud based artifact repository, where I can grab war/jar files from, I have been using git actions to do a maven install and maven deploy to push these maven projects ( installed as war/jar files ) to a cloud based artifact repository, however I need some of my war files to be a specific name which is difficult to do with maven deploys, which renames my war file to a name I don’t want, so I wanted to try and grab the war files that were built when I perform a maven install in git actions, which does have the correct name, and push it to my cloud repository, using actions/download-artifact@v2 I thought I could download the war file and then push it using a curl command which does give me the ability to push to my cloud repository by referencing the downloaded file name as a variable but I don’t know how to reference a downloaded file in a “run:” command.

run: |
FILE_TO_UPLOAD= #variable for referencing downloaded war file
#curl command to push to cloud repository

As for permission denied I tried to just put just the path where I performed a maven install with my curl command and I got this message “/home/runner/work/_temp/ line 1: /home/runner/work/REPONAME/REPONAME/target/filename.war: Permission denied”, if I can figure out how to reference actions/download-artifact@v2 downloaded file then I won’t really have to worry about this error

Okay, in that case your problem has absolutely nothing to do with Actions artifacts, you don’t need to look at uploading/downloading artifacts. :slightly_smiling_face:

You’ll have to figure out the permission error to access your file. One likely reason I can think of is that you’re using a Docker Action that writes the file as root and with permissions that only allow the owner access (in which case you could change the permissions using sudo chmod). But being sure what it is and how to fix it requires more details of your workflow, ideally a look at the workflow logs.

hmmm ok thank you, that sudo chmod command but me on the right track, I’m now getting “line 1: $‘PK\003\004’: command not found” when I try to push the war file? Do you know how to fix this?

That looks really weird, if you need help with that you’ll probably have to share (part of) your workflow file.

heres the code thats causing the error

run: |
           mvn -B -Dmaven.test.skip package
           sudo chmod a+rwx /home/runner/work/REPONAME/REPONAME/target/NEWWARNAME.war
           FILE_TO_UPLOAD=  /home/runner/work/REPONAME/REPONAME/target/NEWWARNAME.war
            #curl command to push to cloud repository

Looks like the gap here is the problem:

If you want to assign a variable in Bash, there must not be spaces around the =. What happens when running that code is that the shell tries to set the environment variable FILE_TO_UPLOAD to an empty value, and then execute the WAR file. That explains the permission denied error before. So you don’t actually have a permission problem, you have a trying-to-run-a-non-executable problem. :wink:

Remove the chmod and pass the path to curl instead of calling it.

hmm I’m now getting this error

/home/runner/work/_temp/ line 4: unexpected EOF while looking for matching ``’

heres the code again I’ll put in the full curl command I’m using, I got rid of FILE_TO_UPLOAD

 run: |
           mvn -B -Dmaven.test.skip package     
           curl -s -w "%{http_code}" -X PUT PATH/TO/CLOUD/REPOSITORY -u USERNAME:PASSWORD -d @${/home/runner/work/REPONAME/REPONAME/target/NEWWARNAME.war}`

The error message tells you the problem: There’s a single backtick at the end of the curl command. No idea what it’s supposed to be doing there. :slightly_smiling_face:

really sorry about that completely my bad, looks like the curl command is running but when it pushes to the cloud repository it’s giving me a blank file, is their something about doing a maven install or trying to grab a war file from the target folder the problem with this?

To make sure the file is not empty when you are uploading it, I would output the file size (using ls -l) and sha sum in your workflow.

And in case the cloud repository is a maven repository, I would try to use mvn install:install-file to upload it instead of curl: Maven – Guide to installing 3rd party JARs

1 Like

That mvn install:install-file command doesn’t push to a cloud repository, it installs a war/jar files that’s in a specific location while you give a custom group and artifact id, as well as a version number, to push to the cloud repository you need to use maven deploy Apache Maven Deploy Plugin – Introduction however I don’t want to use this because I have found no way to change the war file to the name I want, do you know a way to change a war name on a maven deploy?

Sorry, you are right, I was thinking about deploy:deploy-file, which deploys a single file.

And in any case, files deployed with maven will be called {artifactId}-{version}-{classifier}.{type}. As your type is war, the only part you can vary is the classifier. If that does not give you enough flexibility for your file names, you will have to use e.g. curl, but don’t be surprised if the remote repository does some file name validation and reject your files, as it is impossible via Maven to use any artifacts that do not follow the name convention.