Search code examples
jargithubhudsonjenkinspublish

Pushing Jar to github when a Jenkins build succeeds


I have a simple Jenkins build that pulls down my project from github, builds it and reports the status of the build.

I want to have configure Jenkins to publish the resulting JAR file to a TARGET-SNAPSHOTS branch in my project.

Currently my project .gitignore's /target/*

I was looking at GitPublisher but this appears to push the entire build out, rather than just the jar file.

Thoughts on the best way to do this/if this is possible?

Thanks


Solution

  • Since you're using maven and you said the github downloads section is acceptable, you can use the github downloads plugin - https://github.com/github/maven-plugins. I use this for deploying the Riak java client to our downloads section as part of the build.

    In your ~/.m2/settings.xml you need:

    <settings>
      <profiles>
        <profile>
          <id>github</id>
          <properties>
            <github.global.userName>YourGithubUser</github.global.userName>
            <github.global.password>YourGithubPass</github.global.password>
          </properties>
        </profile>
      </profiles>
      <activeProfiles>
        <activeProfile>github</activeProfile>
      </activeProfiles>
    </settings>
    

    Then in your project's .pom something like:

    <profile>
      <id>githubUpload</id>
      <activation>
        <property>
          <name>github.downloads</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.github</groupId>
            <artifactId>downloads-maven-plugin</artifactId>
            <version>0.4</version>
            <configuration>
              <description>${project.version} release of ${project.name}</description>
              <override>false</override>               
              <includeAttached>true</includeAttached>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>upload</goal>
                </goals>
                <phase>install</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    

    (I'm doing it as part of the install phase - you can do however you'd like)

    Then simply add -Dgithub.downloads=true to your maven build -

    mvn install -Dgithub.downloads=true

    The web page for the plugin lists all the options for including/excluding files, etc.