File Rename Issue after publishing the artifact to Nexus - maven

Background: I am renaming a certain set of env specific files in my source code via jenkins pipeline before publishing the artifact to nexus using mvn deploy goal
I'm using mv command to rename the file
mv <env>config.properties config.properties
This does rename the files successfully and when I download the zip from output console of jenkins, I have the renamed files(config.properties) in zip
But the very next time I download it from nexus or from the output console again, It gives a zip file with old file name config.properties. It is somehow renaming it back to original name.
Has anyone faced this before? Any inputs would help

Related

AzureDevops Release - Command Shell "do not have permissions"

I've created a release on Azuredevops with a Command Line Task.
The script is really simple :
Unzip the artifcats and move it to another folder.
But owner's folder is not the same between the Agent Deployment and the repository.
I add chmod 777, it's works, but is not the best answer.
Do you have another solution ?
AzureDevops Release - Command Shell “do not have permissions”
Indeed, to unzip the artifcats and move it to another folder, we could use Extract Files task to complete this:
Extract Files task
Use this task in a build or release pipeline to extract files from
archives to a target folder using match patterns. A range of standard
archive formats is supported, including .zip, .jar, .war, .ear, .tar,
.7z, and more.
BTW, there is an extension to Unzip a directories Zip and unzip directory build task
Hope this helps.

Gradle Could not expand ZIP: is not a ZIP archive

I am trying to unzip an archive file in my Gradle build script.
The archive file exists, and I have checked that it is indeed a zip file by running
file myfile.zip
However, build fails with the following error:
Could not expand ZIP '/.../file.zip': is not a ZIP archive
For Windows:
Please delete the package of the zip file and clean gradle. It will resolve.
One reason this can happen is if the file is damaged or corrupted.
The way to check that is to try manually unzipping the file.
For me, the problem was semi-unrelated. My build directory was owned by root and I was running as a user that did not have permissions to write there. I ended up deleting the dir and the next gradle build handled it.
Yes.. it was due to permission on that file.
For windows:
Give the permission including parent folder as same administrator.
Try it to do it again.
If still not work, delete the zip file and let them create again after 1st step. It will resolve.
I got same error, and after running ./gradlew build --stacktrace found out that resources folder contained Flyway migration file with name "V1.1.98__documents..sql" (double dot). Apparently this caused problems with zipping. Was typo of course.

How to extract and export artifact files (SNAPSHOT.jar) from Jenkins to a network drive

My team has code being built and tested in Jenkins and when the build process is done Jenkins produces a SNAPSHOT.jar file. I need to unpacked the snapshot.jar file and send the extracted files and folders to a network drive. What is the best way to do that?
I've tried a few Jenkins plugins, the most recent being artifactDeployer, but when the plugins deploy the artifacts, as a post-build action, they don't unpack the jar files; I would have to execute a windows batch command after they are deployed to unpack them but I cant because the plugin runs as a "post-build action" and the batch commands are done before the post-build actions. Is there a way to deploy the artifacts and unpack them without using a plugin? Or is there a plugin that will do both? What is the best way to achieve this?
The way I accomplished this was by using 7zip in a Windows batch command as a post-step in the jenkins project configuration.
The command is:
`7z x %WORKSPACE%\target\*.jar -oX:\"mapped network drive location" -y`
This extracts the artifacts out of the snapshot.jar file and places those artifacts into the network drive. I needed the files contained in the snapshot.jar to be sent to the network drive when the build completed. I am new to jenkins and the plugins I tried were post-build actions and only copied the snapshot.jar to a given location; they did not extract the artifacts out of the jar file. That is why I chose this route.

Maven : pom.lastUpdated exists but no jar [duplicate]

I have an Eclipse setup with m2eclipse and subversive. I have imported a maven2 project from svn. But I get the error message that a whole bunch of artifacts are missing (for instance: Missing artifact org.springframework:spring-test:jar:3.0.1.RELEASE:test).
If I look in my repository I see the jar files there but they have an extra extension .lastUpdated. Why is maven appending .lastUpdated to the jars? And more importantly: how can I fix this?
There is no mention of the type lastUpdated in my POMs.
These files indicate to Maven that it attempted to obtain the archive by download, but was unsuccessful. In order to save bandwidth it will not attempt this again until a certain time period encoded in the file has elapsed. The command line switch -U force maven to perform the update before the retry period. This may be necessary if you attempted to build while disconnected from the network.
The method of removing the files works with most versions of maven, but since the files are internal mementos to maven, I would not recommend this method. There is no guarantee that this information is not referenced or held elsewhere and such manipulation can damage the system.
As rperez said, I use to delete all those .lastUpdated files. In Linux I have created a little script to keep it simple:
find -name \*.lastUpdated -exec rm -fv {} +
Just create a file with the previous content and put it on your local Maven repository. Usually it will be ~/.m2/repository.
I installed Maven2 and ran mvn compile from the command line. This seems to have resolved the problem
you might have a problem with some of the artifacts to be retrieved from the repository. for example spring framework has its own repository. this xtension is appended when the artifact cannot fully downloaded. add the spring framework repository to your pom or settings.xml, delete the folder that include the broken jars and start again
If you hit this problem and you're using Nexus, it might be the case that you have a routing rule defined, which is incorrect. I hit this myself and the files it was downloading were correctly named, at the proper URL-s it was looking at, but they were all with the .lastUpdated extension and an error message as contents.
Open your terminal, navigate to your Eclipse's project directory and run:
mvn install
If mvn install doesn't update your dependencies, then call it with a switch to force update:
mvn install -U
This is a much safer approach compared to tampering with maven files as you delete ".lastUpdated".
Use this command inside the .m2/repository dir to rename all files:
for file in `find . -iname *.lastUpdated`; do renamed=$(echo $file | rev | cut -c13- | rev); echo renaming: $file to $renamed; mv $file $renamed; done
This is usefull to not download all sources again.
This not work... The .jar is lost. :(
What I do when I encounter this issue:
Make sure you have the version of the latest 'maven-source-plugin' plugin:
https://maven.apache.org/plugins/maven-source-plugin/usage.html
$ mvn source:jar install
Now if the file *.lastUpdate exist in your local ~/.m2/repositories/your-lib/0.0.1/ directory you can just remove it then run the command above again.
This is a side-effect of a failure to successfully extract from the repository. To get the actual content you want into your repository, check for correct paths to the repository/repositories within your pom file, and resolve certificate/security issues, if any. It is almost invariably one or the other of these issues.
There is no need to delete the .lastUpdated entries, and doing so won't solve your problem.

How to deploy a WAR file which is located in zip file(window) to linux

Right now my situation is like this. I created a war file using eclipse in window. Now i want to zip my war file together with my bash script so that automate installation will occur. Is it anyway so that my bash script can automatically recognize my war file?
You could easily use the zip command. See man zip for more details.
If you want to archive multiples war files in the same directory :
lstPath=""
for warFile in "$DIR"/*.zip; do
lstPath="$lstPath $warFile"
done
zip a.zip lstPath
Or :
lstPath=""
for warFile in "$DIR"/*.zip; do
zip a.zip "$warFile"
done
And if the war files are not in the same directory, you could use the find command ;)

Resources