Kohei Nozaki's blog 

Entries tagged [jenkins]

Deploying with Jenkins Publish Over SSH Plugin


Posted on Friday Feb 28, 2014 at 09:28AM in Jenkins


Environment

  • WildFly 8.0.0.Final
  • Publish Over SSH Plugin 1.11
  • Jenkins 1.551
  • OS X 10.9.2

Requirements

  • Resources are available in git repository
  • The job is parametarized and can specify the tag to be processed
  • The job will build a WAR and deploy it to the remote application server through ssh

Install the plugin

  • Install “Publish Over SSH Plugin 1.11” at Plug-in page.

Create a key-pair

kyle-no-MacBook:~ jenkins$ whoami
jenkins
kyle-no-MacBook:~ jenkins$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/Shared/Jenkins/.ssh/id_rsa): 
Created directory '/Users/Shared/Jenkins/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/Shared/Jenkins/.ssh/id_rsa.
Your public key has been saved in /Users/Shared/Jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
[...] 
The key's randomart image is:
[...]
kyle-no-MacBook:~ jenkins$ ls -l .ssh
total 16
-rw-------  1 jenkins  jenkins  1679 Feb 28 11:55 id_rsa
-rw-r--r--  1 jenkins  jenkins   411 Feb 28 11:55 id_rsa.pub
kyle-no-MacBook:~ jenkins$ 

Put the public-key to the server

kyle-osxserver:.ssh kyle$ cat >> authorized_keys << EOF
> ssh-rsa [...] jenkins@kyle-no-MacBook.local
> EOF

Configure

  1. Click “Manage Jenkins”
  2. Click “Configure System”
  3. Go to “Publish over SSH” section
  4. Enter “/Users/Shared/Jenkins/.ssh/id_rsa” to “Path to Key”
  5. Click “Add” at “SSH Servers”
  6. Enter any logical name to “Name”
  7. Enter IP Address or Hostname of the server to “Hostname”
  8. Enter the user name to login to “Username”
  9. Enter any directory to “Remote Directory”
  10. Click “Test Configuration”
  11. Click “Save” at bottom of the page

Create a job

  1. Create or copy a job that can build the WAR correctly.
  2. As I wrote in How to specify a Git tag to be processed, make a job to can specify a tag to be processed.
  3. Click “Add post-build action”
  4. Click “Send build artifacts over SSH”
  5. Enter “Source files”
  6. Enter “Remove prefix”
  7. Enter “Exec command”

WildFly deploy command example:

/Users/kyle/wildfly-8.0.0.Final/bin/jboss-cli.sh --connect --controller=localhost:49990 --command="deploy hoge-0.0.1-SNAPSHOT.war --force"

Create a tag

kyle-no-MacBook:stock kyle$ git tag v0.1
kyle-no-MacBook:stock kyle$ git tag
v0.1
kyle-no-MacBook:stock kyle$ git show v0.1
commit 87a93c8039bd77b8eb8cbf8fbb522705c6451f1e
[...]

Run

Run the job that created with the parameter of name of tag.

  1. Click “Build with Parameters”

  2. Select a tag to be processed and Click “Build”

Log

...
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/HogeDeploy/workspace/hoge/pom.xml to org.nailedtothex/hoge/0.0.1-SNAPSHOT/hoge-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/HogeDeploy/workspace/hoge/target/hoge-0.0.1-SNAPSHOT.war to org.nailedtothex/hoge/0.0.1-SNAPSHOT/hoge-0.0.1-SNAPSHOT.war
channel stopped
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 /Users/kyle/hoge-0.0.1-SNAPSHOT.war --force"] ...
SSH: EXEC: completed after 4,357 ms
SSH: Disconnecting configuration [osxserver] ...
SSH: Transferred 1 file(s)
Email was triggered for: Always
Sending email for trigger: Always
Sending email to: kyle@example.com
Finished: SUCCESS

References

  1. Publish Over - Jenkins - Jenkins Wiki
  2. jenkinsによるWebSphereへのEARファイルデプロイ - 遅れてやってきたプログラマーの小言
  3. Jenkins、Webから再起動する
  4. Git - タグ
  5. Deploy to WildFly using jboss-cli (Tech Tip #11) | Miles to go 2.0 … | Planet JBoss Community


How to make a Jenkins job to poll SCM periodically


Posted on Sunday Feb 23, 2014 at 11:11AM in Jenkins


Environment

  • Jenkins 1.551
  • git version 1.8.3.4 (Apple Git-47)
  • OS X 10.9.1

Why need it?

  • As I wrote in How to make git commit to trigger run a Jenkins job, Git plugin of Eclipse doesn't fire hooks.
    • Unfortunately, currently EGit not supported it, and maybe will not[1].
  • So we need an alternative way, such as make Jenkins to poll SCM periodically.
    • It seems to I can configure it easily so I just try it here.

How to configure

  1. Go to configure page of a project.
  2. Go to “Build Triggers” section.
  3. Check “Poll SCM”
  4. Enter the schedule that you want in cron-style.
    • The help that placed side of input area might be useful
    • Example for poll at every 15minutes is here:
  5. Save

See the log

  • When any change is detected at polling, we can see that message in log of Jenkins.
    • In this setup, the log file is located at /var/log/jenkins/jenkins.log
Feb 23, 2014 11:24:45 AM hudson.triggers.SCMTrigger$Runner run
情報: SCM changes detected in BuildAndTestHead. Triggering  #22
Feb 23, 2014 11:24:57 AM hudson.model.Run execute
情報: BuildAndTestHead #22 main build action completed: SUCCESS

Remarks

  • I'm not sure that CPU usage or any other resource consumption of git polling.

References

  1. Eclipse Community Forums: EGit » Enabling hooks in EGit


How to send Email at every build with Jenkins


Posted on Saturday Feb 22, 2014 at 09:34PM in Jenkins


Environment

  • Email-ext plugin 2.37.2
  • Jenkins 1.551
  • Apache Maven 3.1.1
  • git version 1.8.3.4 (Apple Git-47)
  • Oracle JDK7u51
  • OS X 10.9.1

Install Email-ext plugin

  • Install Email-ext plugin at plug-in install page of Jenkins

Configure System

“Jenkins Location” section

  1. Enter valid email address to “System Admin e-mail address”

“Extended E-mail Notification” section

  1. Enter your email address to “Default Recipients”

“E-mail Notification” section

  1. Enter your SMTP server name to “SMTP server”
  2. Click “Advanced”
  3. Click “Use SMTP Authentication”
  4. Enter required informations
  5. Check “Test configuration by sending test e-mail”
  6. Click “Test configuration” to send test email
  7. Click “Save” in the bottom of the page

Configure a project to send email at every build

  1. Click “Add post-build action”
  2. Click “Editable Email Notification”
  3. Click “Advanced Settings…”
  4. Click “Add Trigger”
  5. Click “Always”
  6. Save

Test-run

  1. Click “Build Now”
  2. Check Console output and received email
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.497s
[INFO] Finished at: Sat Feb 22 22:27:21 JST 2014
[INFO] Final Memory: 18M/245M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/BuildAndTestHead/workspace/hellojenkins/pom.xml to org.nailedtothex/hellojenkins/0.0.1-SNAPSHOT/hellojenkins-0.0.1-SNAPSHOT.pom
channel stopped
Archiving artifacts
Email was triggered for: Always
Sending email for trigger: Always
Sending email to: kyle@example.com
Finished: SUCCESS

References

  1. Email-ext plugin - Jenkins - Jenkins Wiki


How to deploy an application to WildFly with wildfly-maven-plugin


Posted on Saturday Feb 22, 2014 at 08:39AM in Jenkins


Environment

  • Jenkins 1.551
  • Apache Maven 3.1.1
  • git version 1.8.3.4 (Apple Git-47)
  • Oracle JDK7u51
  • OS X 10.9.1

Consideration of a way to achieve

  • There's the Deploy Plugin of Jenkins, but it only listed JBoss 5.x
  • Thus, I'm going to do deploy through Maven goal with wildfly-maven-plugin, not Jenkins Plugin.

Make pom.xml can deploy

Add wildfly-maven-plugin to pom.xml

  • According to [1], we need plugin definition like that.
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
            </plugin>
  • My whole pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.nailedtothex</groupId>
    <artifactId>hellojenkins</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
            </plugin>
        </plugins>
    </build>
</project>

Run mvn to deploy

According to [1], deploy command is:

mvn wildfly:deploy

Let's try

kyle-no-MacBook:hellojenkins kyle$ mvn clean package wildfly:deploy
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hellojenkins 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hellojenkins ---
[INFO] Deleting /Users/kyle/gits1/hellojenkins/hellojenkins/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellojenkins ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /Users/kyle/gits1/hellojenkins/hellojenkins/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/kyle/gits1/hellojenkins/hellojenkins/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellojenkins ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/kyle/gits1/hellojenkins/hellojenkins/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellojenkins ---
[INFO] Surefire report directory: /Users/kyle/gits1/hellojenkins/hellojenkins/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Running hellojenkins.HelloBeanTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.043 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/kyle/gits1/hellojenkins/hellojenkins/src/main/webapp]
[INFO] Webapp assembled in [19 msecs]
[INFO] Building war: /Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] >>> wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellojenkins ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/kyle/gits1/hellojenkins/hellojenkins/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellojenkins ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellojenkins ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/kyle/gits1/hellojenkins/hellojenkins/src/main/webapp]
[INFO] Webapp assembled in [5 msecs]
[INFO] Building war: /Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.pom (11 KB at 1.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/28/commons-parent-28.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/28/commons-parent-28.pom (49 KB at 94.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.pom (2 KB at 7.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.0.5/maven-core-3.0.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.0.5/maven-core-3.0.5.pom (6 KB at 20.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.pom (4 KB at 11.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.jar
Downloading: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.jar
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar
Downloading: http://repo.maven.apache.org/maven2/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar (28 KB at 37.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-api/3.2.0.Final/xnio-api-3.2.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.jar (251 KB at 252.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-nio/3.2.0.Final/xnio-nio-3.2.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.jar (93 KB at 83.0 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar (226 KB at 157.5 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-nio/3.2.0.Final/xnio-nio-3.2.0.Final.jar (95 KB at 149.7 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-api/3.2.0.Final/xnio-api-3.2.0.Final.jar (480 KB at 162.2 KB/sec)
Downloading: http://repository.jboss.org/nexus/content/groups/public/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar
Downloaded: http://repository.jboss.org/nexus/content/groups/public/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar (256 KB at 57.1 KB/sec)
2 22, 2014 10:07:18 午前 org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.0.Final
2 22, 2014 10:07:19 午前 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.0.Final
2 22, 2014 10:07:19 午前 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.0.Final
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.107s
[INFO] Finished at: Sat Feb 22 10:07:19 JST 2014
[INFO] Final Memory: 20M/245M
[INFO] ------------------------------------------------------------------------
kyle-no-MacBook:hellojenkins kyle$ 

Log of running WildFly:

10:07:19,623 INFO  [org.jboss.as.repository] (management-handler-thread - 13) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.Final/standalone/data/content/74/0b98a41a3c0830172a5df0c5c8d5fdc42be9b6/content
10:07:19,627 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015876: Starting deployment of "hellojenkins-0.0.1-SNAPSHOT.war" (runtime-name: "hellojenkins-0.0.1-SNAPSHOT.war")
10:07:19,649 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016002: Processing weld deployment hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,661 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,666 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016008: Starting weld service for deployment hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,811 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017534: Registered web context: /hellojenkins-0.0.1-SNAPSHOT
10:07:19,832 INFO  [org.jboss.as.server] (management-handler-thread - 13) JBAS018559: Deployed "hellojenkins-0.0.1-SNAPSHOT.war" (runtime-name : "hellojenkins-0.0.1-SNAPSHOT.war")

The application works:

This works too if there's application already deployed which have same name.

Commit to repository

  • Commit changes of pom.xml so that Jenkins can execute the goal that tested above.

Make a Jenkins job

  1. Copy a job that created in previous post
  2. Edit the job that copied
    • Add maven goal “wildfly:deploy”
  3. Click “保存” in the bottom of the page

Run the job

  • I got some errors.
[INFO] XNIO version 3.2.0.Final
[INFO] XNIO NIO Implementation Version 3.2.0.Final
[INFO] JBoss Remoting version 4.0.0.Final
Authenticating against security realm: ManagementRealm
[ERROR] JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.038s
[INFO] Finished at: Sat Feb 22 13:44:10 JST 2014
[INFO] Final Memory: 20M/249M
[INFO] ------------------------------------------------------------------------
Jenkins????????????????
[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) on project hellojenkins: Could not execute goal deploy on /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war. Reason: I/O Error could not execute operation '{
[ERROR] "operation" => "read-attribute",
[ERROR] "address" => [],
[ERROR] "name" => "launch-type"
[ERROR] }': java.net.ConnectException: JBAS012174: Could not connect to http-remoting://127.0.0.1:9990. The connection failed: Authentication failed: the server presented no authentication mechanisms
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/pom.xml to org.nailedtothex/hellojenkins/0.0.1-SNAPSHOT/hellojenkins-0.0.1-SNAPSHOT.pom
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
channel stopped
成果物を保存中
Finished: FAILURE

Why error?

  • In this setup, Jenkins and WildFly are running in different users
  • According to [7], there's an authentication mechanism called “JBoss Local User”, and maybe it can be used with same machine and user, and we might have been used it
  • But Jenkins has its own user in this setup
  • So, we may need another authentication mechanism.

Add a management user to WildFly

  • According to [7], properties file based authentication is enabled by default
  • We can use that command named “add-user” in $WILDFLY_HOME/bin to add a pair of username and password to properties file. usage:
./add-user.sh [USERNAME] [PASSWORD]
  • So let's make it one:
kyle-no-MacBook:bin kyle$ ./add-user.sh admin ***
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Added user 'admin' to file '/Users/kyle/apps/wildfly-8.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'admin' to file '/Users/kyle/apps/wildfly-8.0.0.Final/domain/configuration/mgmt-users.properties'
kyle-no-MacBook:bin kyle$
  • Restart of WildFly is not mandatory.

Edit and commit pom.xml

  • We have to add configuration element as a child of plugin element
                <configuration>
                    <username>USERNAME</username>
                    <password>PASSWORD</password>
                </configuration>
  • Now it is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.nailedtothex</groupId>
    <artifactId>hellojenkins</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
                <configuration>
                    <username>USERNAME</username>
                    <password>PASSWORD</password>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • After edit, we have to commit it again.
  • I guess it is not good to write that environment specific variables like username and password in pom.xml, but I couldn't be found other better idea, so I just go this way this time.

A way to specify that username and password in the MAVEN_OPTS

  • According to [10], entries that wrote “User property is:” are can be specified in the MAVEN_OPTS. like that:
    • That configuration can be set after click “Advanced…” in the build section of configuration page of a project.
    • Now, we don't need to specify authentication information in pom.xml.

Run the job again

[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [3 msecs]
[INFO] Building war: /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[WARNING] Failed to getClass for org.wildfly.plugin.deployment.DeployMojo
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins ---
[INFO] XNIO version 3.2.0.Final
[INFO] XNIO NIO Implementation Version 3.2.0.Final
[INFO] JBoss Remoting version 4.0.0.Final
Authenticating against security realm: ManagementRealm
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.672s
[INFO] Finished at: Sat Feb 22 14:37:01 JST 2014
[INFO] Final Memory: 21M/317M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/pom.xml to org.nailedtothex/hellojenkins/0.0.1-SNAPSHOT/hellojenkins-0.0.1-SNAPSHOT.pom
channel stopped
成果物を保存中
Finished: SUCCESS
  • Succeed but weird warning “Failed to getClass for org.wildfly.plugin.deployment.DeployMojo” remained.
    • I have googled it but there's no information about it.

Remarks

  • Maybe a way introduced at [8] can be a good idea to achieve that switch various deployment destinations.
    • We can switch the destination easily through use of Maven profiles
  • If you don't want to deploy when test failed, follow steps in [9] , and set parameter “-Dmaven.test.failure.ignore=false” to the MAVEN_OPTS.
  • When we have to deploy to remote Unix systems, Publish Over SSH Plugin[11] sounds very useful than the procedure of this post.

References

  1. WildFly Maven Plugin - Deploy/Undeploy Examples
  2. Eclipse Community Forums: Hudson » Deploy to Wildfly (jBoss 8.x?)
  3. The 10 Most Important Projects Hosted On Codehaus.org
  4. Deploy Plugin - Jenkins - Jenkins Wiki
  5. JenkinsでJBossAS7にデプロイしようと思ったので - 日々常々
  6. WildFly Maven Plugin - Deploy/Undeploy Examples
  7. Security Realms - WildFly 8 - Project Documentation Editor
  8. Jboss / Wildfly maven plugin to deploy on localhost/remote server
  9. [#JENKINS-959] hudson deploys maven artifact even if test has failed - Jenkins JIRA
  10. WildFly Maven Plugin - wildfly:deploy
  11. Publish Over SSH Plugin - Jenkins - Jenkins Wiki


How to specify a Git tag to be processed with Jenkins


Posted on Friday Feb 21, 2014 at 08:35PM in Jenkins


Environment

  • Jenkins 1.551
  • Apache Maven 3.1.1
  • git version 1.8.3.4 (Apple Git-47)
  • Eclipse Kepler SR1
  • Oracle JDK7u51
  • OS X 10.9.1

Create a tag

  1. Open context menu of the project - Team - Advanced - Tag

  2. Enter tag name and Tag message, then click OK

  3. To check created tag, Open context menu of the project - Team - Show in Repositories View

  4. Confirm it appeared.

Modify a resource of HEAD

  • In order to check that build will processed with the tag specified, so just do some modify a resource of HEAD.
    • Make sure that you are in the master branch.
    • Procedure to switch: Team - Switch To - master
  • I have modified a resource that returns a message to Servlet. now it shows like that:
  • After modify, we have to commit it.

Install Git Parameter Plugin

I got trouble that the plugin not showing any tags, so I have stopped using this plugin. there are some people who reporting same problem[6]. If skipped this, we can't see the list of tags in the repository, but we can specify a tag manually.

This plugin makes easy that specify a tag to be processed.

Make a Jenkins job

  1. Copy a job that created in previous post
  2. Check “This build is parameterized”
  3. Click “Add Parameter”
  4. Click “Git Parameter”
  5. Enter “tag” to “Name”
  6. Enter “*/master” to “Branch”
  7. Find the section named “Source Code Management”
  8. Enter “${tag}” to “Branch Specifier”
  9. Click “Save”

Try Parameterized build

  1. Click this:
  2. Select a tag that created above
  3. Click “ビルド”

Check console output of Jenkins

ユーザーanonymousが実行
ビルドします。 ワークスペース: /Users/Shared/Jenkins/Home/jobs/DeploySpecifiedTag/workspace
Fetching changes from the remote Git repository
Fetching upstream changes from file:///Users/kyle/gits1/hellojenkins
Checking out Revision 9d88b2abe381c6e2c915bbbf0ddeec09119b6f04 (v1.0)
Parsing POMs
...
  • We can see that build was processed with tag named “v1.0”

References

  1. Can I get Jenkins to build a git tag from a passed in parameter? - Stack Overflow
  2. Jenkins and the Git Branch Selection - Sourceprojects.org
  3. Git Parameter Plugin - Jenkins - Jenkins Wiki
  4. Jenkinsで外部パラメータで与えたブランチを対象にビルドできるようにしておくと凄惨性あがって墓ドル - ( ꒪⌓꒪) ゆるよろ日記
  5. Hudson Growl Pluginでビルド結果をGrowlへ通知 | skmks
  6. Doesn't show any tags or revisions · Issue #2 · lukanus/git-parameter