I want to create a war file using hudson. I did with following steps.
1.I have created the build.xml in my project.
2.In that ant file I am providing the targets to compile the application and create the war.
3.Then I have created the hudson job where I am providing the build option i.e invoke by ant .and In deploy option I am providing the the weContainer where I have to deploy the war.
4.Its creating the war and also deploy it on webcontainer.
But is it right way to do it?
Thanks,
You can use maven cargo plugin and copy artifact plugin to deploy war using hudson.
Provide your server admin. Add users in apache tomcat.
<!-- Configuration for the Maven build -->
<build>
<!-- The plugins tag as mandated by maven -->
<plugins>
<!-- Start's the plugin tag for Cargo! -->
<plugin>
<!-- Cargo Group Id -->
<groupId>org.codehaus.cargo</groupId>
<!-- Cargo's Artifact Id -->
<artifactId>cargo-maven2-plugin</artifactId>
<!-- This the most important part of the setup -->
<configuration>
<!--
When Cargo starts the container, the following tag instructs it to
wait for you to kill the session with Crtl-C
-->
<wait>true</wait>
<!--
The following tag details the container you want to
deploy to.
-->
<container>
<!--
Specifying "tomcat6x" is very important! This one tripped me up
for quite a while. The issue is that instead of being an
identifier for you, "tomcat6x" is an identifier for Cargo that
you want to deploy your webapp in Tomcat 6.x. I had initially
thought otherwise and hence just dropped the 'x', making it
"tomcat6", but that never worked.
-->
<containerId>tomcat6x</containerId>
<!--
Type == Installed means that you want to deploy to a container
that's installed on your computer
-->
<type>installed</type>
<!-- The home folder for your local Tomcat -->
<home>${catalina.home}</home>
</container>
<configuration>
<!--
This is another one that confused me for long. Its not enough to
specify 'installed' in the container tag. You have to now specify
another configuration with type == existing and re-issue the home
path
-->
<type>existing</type>
<home>${catalina.home}</home>
</configuration>
<!--
Cargo has the notion of a 'deployer' in which you specify
'deployables'
-->
<deployer>
<!-- You have to again specify that the type for the deployer -->
<type>installed</type>
<deployables>
<!-- This deployable specifies the webapp you want to deploy -->
<deployable>
<groupId>com.dpillay.oworld</groupId>
<artifactId>oworld-webapp</artifactId>
<type>war</type>
</deployable>
</deployables>
</deployer>
</configuration>
<!--
Executions specify the targets that you want to run during build
-->
<executions>
<!--
Maven has the concept of a 'phase' which can be thought of a
collection of goals. Hence here we are specifying that during the
'install' phase first deploy the webapp to the container specific
folder and then start the container. Both 'deployer-deploy' and
'start' are cargo specific goals.
-->
<execution>
<id>verify-deploy</id>
<phase>install</phase>
<goals>
<goal>deployer-deploy</goal>
<goal>start</goal>
</goals>
</execution>
<!--
Specifying that during the 'pre-clean' phase, Cargo should first
stop the container.
-->
<execution>
<id>clean-undeploy</id>
<phase>pre-clean</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Related
I am using DOJO toolkit and after upgrading to use the closure compiler, I noticed I needed to transpile to ES5 BEFORE the dojo build util does it's job in order to take advantage of newer ES6+ features.
So I am using babel-maven-plugin to accomplish this.
Everything is working fine with the exception that the ...spread operator is not transpiling.
Do I need to download the #babel/preset-env package as well to set the preset option? or is there an option I am missing?
After further discovery there is no need to download any preset package.
babel-standalone takes in preset options through its API as defined here and use in the babel-maven-plugin here.
The preset option is not passed to the Babel API like defined in a .babelrc config file. It is passed in without the preset- prefix. So to get the #babel/preset-env preset option you need to simply pass in env.
So to round this out, here are the common presets and how you would pass them through to the API:
#babel/preset-env --> env
#babel/preset-react --> react
#babel/preset-flow --> flow
#babel/preset-typescript --> typescript
So in order to use babel-maven-plugin I need to set up the pom.xml as follows:
<plugin>
<groupId>com.jarslab.maven</groupId>
<artifactId>babel-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>js-transpile</id>
<phase>process-resources</phase>
<goals>
<goal>babel</goal>
</goals>
<configuration>
<verbose>true</verbose>
<babelSrc>./js/babel/babel.min.js</babelSrc>
<sourceDir>./js</sourceDir>
<targetDir>./js</targetDir>
<presets>env</presets>
</configuration>
</execution>
</executions>
</plugin>
I'm struggling getting the F8 CD-Pipeline to work on OpenShift. I use a Jenkinsfile downloaded from the F8 Jenkinsfile Library for Maven builds with steps "CanaryReleaseAndStage". The stage deploy step there looks like the following:
stage('Rollout Staging') {
kubernetesApply(environment: envStage)
}
I looked up the implementation of kubernetesApply() from the Kubernetes Pipeline Plugin. If no file parameter is present in the call (like here) it applies the Kubernetes/OpenShift resources defined in file "target/classes/META-INF/fabric8/openshift.yml", which is generated upon build.
In this file (which is also uploaded as artifact to the nexus, so I can easily fetch it) there are three resources defined:
A Service
A Deployment config, containing a Docker image reference (without tag), also containing a ConfigChange trigger listening for an ImageStreamTag 'my-project:latest'
A Route
... but no ImageStream. However on the build log I see that an image stream definition apparently got generated on a different file:
[INFO] F8: Found tag on ImageStream my-project tag: sha256:c15b56841387a7e0aea960020ccf2efb48f21bd4d12d826e2cd04a94f4d9d748
[INFO] F8: ImageStream my-project written to /home/jenkins/workspace/my-project-dir/target/my-project-is.yml
But I'm afraid that one never gets applied to Kubernetes. Hence there is no image stream in the staging project.
In this configuration the staging deployment cannot even deploy the pod. If I add an image stream manually to the staging project it deploys but is never updated when new builds occur.
I've updated to the newest fabric/jenkins image 2.2.331, but it also does not seem to work here.
My pom.xml (parts essential for f8 building):
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>myproject/artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<fabric8.mode>openshift</fabric8.mode>
<fabric8.build.strategy>docker</fabric8.build.strategy>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.2.28</version>
<configuration>
<images>
<image>
<name>fabric8/my-project</name>
<build>
<dockerFileDir>${project.basedir}/src</dockerFileDir>
<dockerFile>Dockerfile</dockerFile>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So I'd like to know:
How is the CD pipeline supposed to work regarding updates to the staging deployments here?
Why is this image stream definition created if it is not applied. Am I missing some configuration here maybe.
Thanks for any insight!
Any chance of seeing your pom.xml and full build? It sounds like you are using fabric8-maven-plugin right? Its doing a S2I binary build and generating an image stream? It just sounds like somethings going wrong and the generated image stream isn't being included in your target/classes/META-INF/fabric8/openshift.yml maybe?
I wonder if something is going wrong in the order of your maven goals or something (e.g. typically fabric8:resource is first, then fabric8:build which then adds the ImageStream into the generated YAML files)
I'm using the com.samaxes.maven minify-maven-plugin to minify a collection of JS source files written using some of the ES6 features Google Closure supports. Here's the relevant configuration in my POM:
<!-- minify-maven-plugin: Minification using Google Closure -->
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<!-- Creation of the common-[version].js file -->
<execution>
<id>common-minify</id>
<phase>prepare-package</phase>
<configuration>
<charset>UTF-8</charset>
<jsSourceDir>.</jsSourceDir>
<jsSourceFiles>
...
</jsSourceFiles>
<jsFinalFile>./js/common-${project.version}.js</jsFinalFile>
<jsEngine>CLOSURE</jsEngine>
<closureLanguageIn>ECMASCRIPT6</closureLanguageIn>
<closureLanguageOut>ECMASCRIPT5</closureLanguageOut>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
<!-- 2 other similarly configured executions are here. -->
...
</executions>
</plugin>
The problem is, when I run the maven goal this configuration, I get the following error message:
[INFO] Creating the merged file [common-1.8.24.js].
[INFO] Creating the minified file [common-1.8.24.min.js].
Jan 03, 2017 12:03:06 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: [1mcommon-1.8.24.js:5577: [31mERROR[39m - object literals cannot contain duplicate keys in ES5 strict mode[0m
supportsDataForwarding: function () {
^
This looks to me like Google Closure is trying to compile using ES5 Strict mode, even though I specified the non-strict ECMASCRIPT5 mode in my <closureLanguageOut> option (see doc here). Why is it not disabling strict mode?
i had the same problem and found a way to let the minify-maven-plugin not fail the build in case it complains about ES5 strict mode:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<execution>
<id>default-minify</id>
<phase>process-resources</phase>
<configuration>
<charset>UTF-8</charset>
<closureWarningLevels>
<es5Strict>OFF</es5Strict>
</closureWarningLevels>
...
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
You may further fine-tune using the following documentation How to tell closure compiler which warnings you want. Hope this helps :)
I need to configure jetty running from the maven cargo plugin to point it at static content, Ive looked through the jetty documentation and I cant see how to apply the configuration to jetty when it is running as part of cargo. I want to configure the webApp section and set the resource base as my angular app built as a module of this build:
<execution>
<id>start jetty - angular webapp</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
</container>
<webApp>
<resourceBases>
<contextPath>/</contextPath>
<resourceBase>../calculator-web/dist</resourceBase>
</resourceBases>
</webApp>
<configuration>
<properties>
<cargo.servlet.port>11000</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</execution>
Jetty starts but it seems to ignore this configuration and I just get a 404 for my index.html file.
Can somebody point me in the right direction please?
Although cargo does not seem to support Jetty's reload or automatic hot redeploy feature directly, at least you can serve your 'unfinished' static content and immediately pick up changes, e.g. during development while running an embedded container.
My current solution is to reconfigure Jetty's DefaultServlet, pointing the resourceBase to the project's 'live' source directory (e.g. ${basedir}/src/main/webapp) rather than the deployable's default (build) <location/> (e.g. ${project.build.directory}/${project.build.finalName}), and (just to be sure) disabling useFileMappedBuffer to avoid file locking in Windows:
Copy Jetty's webdefault.xml (from e.g. target/cargo/configurations/jetty.../etc/ when running the cargo container as standalone) to, for instance, src/main/jetty/my-webdefault.xml
Modify its DefaultServlet initialization parameters:
<web-app ...> <!-- src/main/jetty/my-webdefault.xml -->
:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
:
<init-param> <!-- relative to pom.xml, or wherever cargo runs -->
<param-name>resourceBase</param-name>
<param-value>./src/main/webapp</param-value>
</init-param>
<init-param> <!-- to avoid file locking in Windows, use: false -->
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
</web-app>
Have the cargo-maven2-plugin copy the new config file my-webdefault.xml into the (Jetty) container's etc/ directory:
<project ...> <!-- pom.xml -->
:
<build>
:
<plugins>
:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>...</version>
<configuration>
<container>...</container>
<configuration>
<configfiles>
<configfile>
<file>${basedir}/src/main/jetty/my-webdefault.xml</file>
<tofile>etc/webdefault.xml</tofile>
</configfile>
</configfiles>
<properties>...</properties>
</configuration>
<deployables>...</deployables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run with mvn clean verify cargo:run
PS. My attempts with a scratch.xml to trigger a simple static content ResourceHandler in a separate context (e.g. /static) were without success.
We develop multiple branches of a project concurrently. Each developer has multiple working copies, each working copy uses its own DB schema. (There will typically be a working copy per branch, but sometimes even more than one working copy per branch.) We need to let Maven know the DB credentials (for the db-migration plugin, for unit tests, for the dev instance of the servlet).
We can't put the credentials in the pom.xml because each developer might use different DB schema names. We can't put the credentials in settings.xml because each developer uses more than one schema.
Where do we put the credentials?
For example, http://code.google.com/p/c5-db-migration/ describes that the DB credentials need to be present in pom.xml but I would like to externalize them out to a file that's not under revision control.
You could put them into a properties file inside the project directory but which is excluded from source control.
With Maven it's possible to read properties from an external file by using a <build><filters><filter> element as instructed here.
Read following answers:
How to read an external properties file in Maven
Reading properties file from Maven POM file
Read a file into a Maven property
or just:
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
</execution>
<configuration>
<files>
<file>dev.properties</file> <======== IT IS!!!!!
</files>
</configuration>
</executions>
</plugin>
</plugins>
</build>
</project>