Deploying ear with jenkins executing shell script - shell

I'm trying to deploy a .ear file to my test environment using Jenkins.
The web application is running on Bea Weblogic 9.2, so i though the easiest way to do this is just execute the following script in the post build steps (add post buils steps--->execute shell):
java weblogic.Deployer -adminurl t3://22.33.44.55:8001 -username myUserName -password myPassword -deploy -name earfilename -targets AdminServer -source C:\apps\sample.ear
Assuming that this will work, i'm sure you will agree with me that this does not make sense bacause the -source is pointing at my local ear. I want instead to deploy the ear file that was just builded from jenkins (which is the result of the SVN commit).
So my final question is: is there any environment variable i can put in my script to get the -source (path to the ear just builded) and -name (the name of the artifact changes with each version)?
Thanks in advance

source parameter doesnt need to have the filename with it, it should be C:\apps\ and put name as the application name. you can also add a one liner command to remove the already existing apps before the new build is created so that apps folder only has one file. If the ear file resides in a remote server use -remote option with the command.
e.g
java -cp $CLASSPATH weblogic.Deployer -adminurl ADMIN_URL:PORT -username weblogic -password weblogic1! -distribute app.war -name appname -targets AdminServer -debug
-usenonexclusivelock
you can also check the name of ear file with find command, store it in a variable and use that variable in the command.

Related

Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar?

I follow the instructions in https://spring.io/guides/gs/spring-boot/#scratch, but when it says to run:
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
the build fails with the above error.
There is message before the failure that says:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8.1/userguide/command_line_interface.html#sec:command_line_warnings
but everyone online says that's just a warning.
The build doesn't appear to create or download build/libs/gs-spring-boot-0.1.0.jar.
Currently completely blocked on first attempt to use Gradle.
I just had this problem.
The tutorial is in error in what you need to run. It should be
$ gradlew build && java -jar build/libs/gs-rest-service-0.1.0.jar
I think that they updated the code, but forgot to update the tutorial.
I had the same issue when build a simple project with Maven on Intellij IDEA. (Ubuntu 18.04.2).
Just typed terminal (in project directory):
$ sudo mvn package
$ java -jar ./target/(your-project-name)-(<version> at pom.xml).jar
For example my project name is hello-world-spring and version name in pom.xml is <version>0.0.1-SNAPSHOT</version>, I have to type:
$ sudo mvn package
$ java -jar ./target/hello-world-spring-0.0.1-SNAPSHOT.jar
Maybe this method can work for gradle as well.
Please check the path of the jar file build/libs/gs-spring-boot-0.1.0.jar. For your case, the jar might be in a different folder. If your code is in a module in the main project, then the jar will be in the build folder of the module.
If you git clone the repo, then the tutorial works. If you "To start from scratch, move on to Build with Gradle.", then the tutorial doesn't work. There are missing setup steps.
I got the same issue and I changed the command to java -jar target/rest-service-0.0.1-SNAPSHOT.jar (I checked the .jar file in target folder and found that the file name was incorrect).
Parent folder of my project was having spaces in it's name, i changed it to the underscore and it worked.
Looked at the command line as it was in the official guide:
./gradlew clean build && java -jar build/libs/gs-actuator-service-0.1.0.jar
First, the above command line has two parts:
(1) ./gradlew clean build //Use gradle wrapper to build
(2) java -jar build/libs/gs-actuator-service-0.1.0.jar //To run an application packaged as a JAR file
Now, one might run into issues with one part or both parts. Separating them and running just on thing at a time helped troubleshoot.
(1) didn't work for my Windows, I did the following instead and that built the application successfully.
.\gradlew.bat clean build
Now moving to (2) java -jar build/libs/gs-actuator-service-0.1.0.jar
It literally means that "Run a jar file that is called gs-actuator-service-0.1.0.jar under this directory/path: build/libs/" Again, for Windows, this translates to build\libs\ , and there's one more thing that may catch you: The jar file name can be slightly different depending on how it was actually named by the configuration in initial/setting.gradle:
rootProject.name = 'actuator-service'
Note that the official guide changed it from 'gs-actuator-service' to 'actuator-service' in their sample code but hasn't updated the tutorial accordingly. But now you know where the jar file name comes from, that doesn't matter anymore, and you have the choice to rename it however you want.
Having all the factors adjusted, below is what eventually worked in my case:
java -jar build\libs\actuator-service-0.0.1-SNAPSHOT.jar
or
java -jar C:\MyWorkspace\Spring\gs-actuator-service\initial\build\libs\actuator-service-0.0.1-SNAPSHOT.jar //with fully qualified path
If you are curious where does "-0.0.1-SNAPSHOT" come from, here it is:
in build.gradle
version = '0.0.1-SNAPSHOT'
Again, you have the choice to modify it however you want. For example, if I changed it to 0.0.2-SNAPSHOT, the command line should be adjusted accordingly
java -jar build\libs\actuator-service-0.0.2-SNAPSHOT.jar
Reference: https://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html
Because you are trying to execute .jar file that doesn't exist. After building the project go to ./build/libs and check the name of freshly built .jar file and then in your project directory run:
./gradlew build && java -jar build/libs/name-of-your-jar-file.jar
or you can set version property to empty string in your build.gradle file
version = ''
after that:
./gradlew build && java -jar build/libs/your-project-name.jar
For Windows, these commands solved the problem: "Error: Unable to access jarfile springboot.jar":
cd target
java -jar springboot-0.0.1-SNAPSHOT.jar
run ./mvnw package
Now a folder named target is created and you can see a jar file inside it.
then execute java -jar target/<jarfilename>

can't access jenkins configuration file dir

I would like to know why, after running on my console:
java -jar jenkins.war
and going after the installation process, I can't access the jenkins configuration dir in the same dir as the war file. Where should I look this dir in case I wanna backup ?.
Default location for Jenkins on a Windows machine is C:\Users\<USERNAME>\.jenkins. You can specify this location by specifying JENKINS_HOME, like this:
java -DJENKINS_HOME=C:\path\to\jenkins\home -jar jenkins.war

Can we configure settings.xml to our own location in maven

Recently I am working with Apache Maven in Windows machine.
I am executing maven from Command Prompt every time.
I know that MAVEN will pick its settings.xml from C:\Users\abc\.m2\settings.xml
Question: Can't I change this settings.xml to be picked from my own provided location instead of default location, like C:\Users\abc\.m2\settings.xml
That is, instead of C:\Users\abc\.m2\settings.xml location I will configuring it in F:\myFolder\settings.xml.
If so, what are the steps I need to follow and check?
You can change the location of user settings using the -s option from the command line:
-s,--settings <arg> Alternate path for the user settings file
You could hence invoke Maven as following:
mvn clean install -s F:\myFolder\settings.xml
If you don't want to specify it at each and every invocation, since Maven 3.3.1 you can specify a .m/config folder in your project folder and a maven.config file in it providing this option.
The .m/config/maven.config file would have in your case the following content:
-s F:\myFolder\settings.xml
And it will be applied to all Maven invocation for that project.

How to deploye .war file in jboss server using shell script

I am on RedHat, using Jboss 5.x and Jenkins. My Jenkins is building the project perfect. I am coping the war file to deploy folder of Jboss with shell script.
When I am running the command on my terminal
scp source/example.war destination/deploy
scp command is able to copy the .war file into deploy folder and through url I am able to access it.
But the when I am writing the same command on jenkins it throws an error.
Permission denied
Build step 'Execute shell' marked build as failure
I guess it is because jenkins try to write the file and it does not have permission.
so how do i do that??
If you are using SCP to copy your file from the Jenkins server to your Jboss server, you should declare the public SSH key of your jenkins user on the Jboss Server.
Please have a look to this answer: add a publickey to server for SCP

How do I build my Spring MVC project with maven then run on my vfabric tomcat server, entirely with command line?

My server runs fine from Eclipse, but I can't get it to run from command line.
Here's what I'm trying, unsuccessfully ("hp-dsat" is the name of my project and also the database name, and project folder that contains pom.xml):
# stop server
cd ~/TcServer/
./tcruntime-ctl.sh myserver/ stop
# import clean sql
dropdb hp-dsat
createdb
psql hp-dsat < ~/hp-dsat/src/main/webapp/resources/data.sql
# build project with maven (doing something wrong here?)
cd ~/hp-dsat
mvn compile
mvn package -Dmaven.test.skip=true
# move the war file to my TcServer
mv -f ~/hp-dsat/target/hp-dsat-1.0.0-BUILD-SNAPSHOT.war ~/TcServer/myserver/webapps/ROOT.war
# start the server back up
cd ~/TcServer/
./tcruntime-ctl.sh myserver/ start
The server starting, but when I visit myserver.com:8080 or myserver.com:8080/hp-dsat (second one is with the context path) it just returns nothing but a blank page.
The thing is, it works if I build the project in eclipse. I just need to figure out how to do it from command line to make a build script to use on a git hook. The server doesn't have eclipse either.
You need to use the cargo deploy plugin in maven, and also might want to look at using jenkins, or another CI server aswell.

Resources