$ mkdir trader-stable.git $ cd trader-stable.git $ git init --bare Initialized empty Git repository in /Users/Shared/trader-stable.git/ $
Entries tagged [jenkins]
Configuring automatic push by successfully build
TweetPosted on Sunday Mar 01, 2015 at 11:19PM in Jenkins
Making Jenkins to push to an another remote repository if build finishes successfully.
Recipe
-
Create a bare repository
-
Click
Add Repository
-
Enter
Repository URL
-
Click
Advanced…
-
Enter
stable
toName
-
Click
Add post-build action
⇒Git Publisher
-
Check
Push Only If Build Succeeds
-
Click
Add Tag
-
Enter
$BUILD_NUMBER
toTag to push
-
Check
Create new tag
-
Enter
stable
toTarget remote name
-
Click
Save
Test
$ pwd /Users/kyle/tmp/trader $ echo 'push if succeeds test' >> hi.txt $ git commit -am 'push if succeeds test' $ git push origin master
Jenkins said Pushing tag 8 to repo stable
$ git remote add stable /Users/Shared/trader-stable.git $ git fetch stable remote: Counting objects: 1, done. remote: Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. From /Users/Shared/trader-stable * [new tag] 8 -> 8 $
Configuring automatic build by push for git repository
TweetPosted on Sunday Mar 01, 2015 at 07:15PM in Jenkins
We can start the build by send request to following URL.
http://YOURHOST/jenkins/job/PROJECTNAME/build
Recipe
In my case, Jenkins is deployed in /
, and the server is running on port 18080
. so the command to start a build of the job named trader
will be:
curl http://localhost:18080/job/trader/build
So put following shell script into $ORIGIN_BARE_REPOSITORY/hooks/post-receive
and execute chmod +x post-receive
.
#!/bin/sh curl http://localhost:18080/job/trader/build
Testing
Push some modification as follows:
$ echo hook test >> hi.txt $ git add hi.txt $ git commit -m 'hook test' $ git push origin master
Check the build was run automatically as expected, and the output.
Creating a simplest Jenkins job against a git repository
TweetPosted on Sunday Mar 01, 2015 at 05:45PM in Jenkins
-
Click
New Item
-
Enter
trader
inItem name
and selectBuild a free-style software project
-
Select
Git
and enterRepository URL
-
Click
Add build step
-Execute shell
-
Enter
cat hi.txt
intoCommand
-
Click
Save
-
Click
Build Now
-
Click a Build History which just created by build
-
Click
Console Output
Lean example of integration test Maven project for WildFly
TweetPosted on Monday Feb 23, 2015 at 11:20PM in Technology
I created similar example before, but it was redundant. I created more lean version so leave here with some notes. check my GitHub repository for details.
The project contains AppServer class, which extends ExternalResource
so it can be used with @Rule
annotation of JUnit as follows. note that mavenit
is the name of WAR file to be tested.
public class HelloImplIT { @ClassRule public static AppServer appServer = new AppServer(); private static Hello sut; @BeforeClass public static void beforeClass() { sut = appServer.lookup("mavenit", HelloImpl.class, Hello.class); } @Test public void test() { Assert.assertEquals("Hello world!", sut.hello()); } }
The project is easy to use with both of IDE and standalone. to run IT classes with IDE, you need to launch the application server, deploy the project as WAR package, then run a IT class from IDE. if you launched the server at not 8080
port, specify the port in app-server.port
system property.
To run IT classes in standalone Maven, use following command. it automatically launches WildFly instance with port offset of 30000
, deploy the WAR file, running IT classes, undeploy the WAR and stops WildFly. the command is intended to use from a Jenkins job.
mvn verify -Pintegration-test-with-wildfly \ -Djava.home=/Library/Java/JavaVirtualMachines/jdk8/Contents/Home/jre \ -Djboss-as.home=/Users/kyle/servers/wildfly-8.2.0.Final \ -Dwildfly.port=39990 \ -Dapp-server.port=38080 \ -Dwildfly.jvmArgs="-Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-mavenit -Djboss.socket.binding.port-offset=30000 -ea"
You can configure following parameters through command line argument:
-
JAVA_HOME
⇒-Djava.home
-
WildFly distribution ⇒
-Djboss-as.home
-
jboss.server.base.dir
⇒ inside-Dwildfly.jvmArgs
-
Port offset ⇒
-Djboss.socket.binding.port-offset
inside-Dwildfly.jvmArgs
. you need to set-Dwildfly.port
and-Dapp-server.port
accordingly.
Deploying after integration test with Jenkins
TweetPosted on Wednesday Mar 05, 2014 at 04:09PM in Jenkins
Requirements
- I want to deploy the production resource after integration test.
- But some resources are environment-specific.
- So, after integration test succeeded, I want to replace such resources for production version.
How to achieve it?
- The deployment job is need to be a parameterized job.
- After integration test completed, then another mvn starts at post-build step of Jenkins.
- This mvn does only package goal with no tests.
- Deployment will be executed by SSH deploy plugin at post-build action of Jenkins.
How to apply this way to a Jenkins job?
- Create a parameterized job that can integration-test and deployment be done successfully.
- I assumed a job similar to one created at another my posting Deploying with Publish Over SSH Plugin
- Go to job configuration page
- Click “Add post-build step”
- Click “Invoke top-level Maven targets”
- Select “Run only if build succeeds”
- Select Maven Version “Default”
- Not (Default) which one with enclosed in parentheses. it won't work.
- Enter “Goals”
- Click “Advanced…”
- Enter “POM”, “Properties”.
- “hogeApp.environmentId=prod” triggers to Maven to include production resources in my pom.xml.
- Ensure that there is a post-build action which deploys the artifact to the production environment.
- Click “Save” of bottom of the page.
Log
Jenkins job output
... [INFO] --- maven-failsafe-plugin:2.16:verify (default) @ switch --- [INFO] Failsafe report directory: /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/failsafe-reports [JENKINS] テスト結果の記録 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.169s [INFO] Finished at: Wed Mar 05 16:25:53 JST 2014 [INFO] Final Memory: 22M/318M [INFO] ------------------------------------------------------------------------ [JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/pom.xml to org.nailedtothex/switch/0.0.1-SNAPSHOT/switch-0.0.1-SNAPSHOT.pom [JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch.war to org.nailedtothex/switch/0.0.1-SNAPSHOT/switch-0.0.1-SNAPSHOT.war channel stopped [workspace] $ /Users/kyle/apps/apache-maven-3.1.1/bin/mvn -f switch/pom.xml -Dtag=v0.1 -Dmaven.test.skip=true -DhogeApp.environmentId=prod clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building switch 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ switch --- [INFO] Deleting /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ switch --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ switch --- [INFO] Compiling 1 source file to /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ switch --- [INFO] Not copying test resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ switch --- [INFO] Not compiling test sources [INFO] [INFO] --- maven-surefire-plugin:2.16:test (default-test) @ switch --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-war-plugin:2.4:war (default-war) @ switch --- [INFO] Packaging webapp [INFO] Assembling webapp [switch] in [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch] [INFO] Processing war project [INFO] Copying webapp webResources [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/src/main/webapp/_prod] to [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch] [INFO] Copying webapp resources [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/src/main/webapp] [INFO] Webapp assembled in [46 msecs] [INFO] Building war: /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.595s [INFO] Finished at: Wed Mar 05 16:26:01 JST 2014 [INFO] Final Memory: 15M/245M [INFO] ------------------------------------------------------------------------ SSH: Connecting from host [kyle-no-MacBook.local] SSH: Connecting with configuration [osxserver] ... SSH: EXEC: STDOUT/STDERR from command [/Users/kyle/wildfly-8.0.0.Final/bin/jboss-cli.sh --connect --controller=localhost:49990 --command="deploy switch.war --force"] ... SSH: EXEC: completed after 3,256 ms SSH: Disconnecting configuration [osxserver] ... SSH: Transferred 1 file(s) Finished: SUCCESS
- Deployment succeeded as expectedly.
- After integration-test completed, another mvn was kicked, and it builds the package for production without testing once again.
Check the deployed application
kyle-osxserver:~ kyle$ telnet localhost 48080 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET /switch/ HTTP/1.0 HTTP/1.0 200 OK Connection: close X-Powered-By: Undertow 1 X-Powered-By: JSP/2.2 Set-Cookie: JSESSIONID=gLpwDJ37tu-Uoxd0r9pWD2wH.kyle-osxserver; path=/switch Server: Wildfly 8 Content-Type: text/plain;charset=UTF-8 Date: Wed, 05 Mar 2014 07:27:29 GMT This value came from context-param defined in /src/main/webapp/_prod/WEB-INF/web.xml This value came from /src/main/resources/common.properties This value came from /src/main/resources/_prod/env-specific.properties Connection closed by foreign host. kyle-osxserver:~ kyle$
- I deployed a sample application created in Maven - Switching environment specific configuration files.
- I can see that pom.xml of it was included resources for production expectedly.
References
Tags: jenkins