Skip to content

Instantly share code, notes, and snippets.

@t-yuki
Last active November 24, 2016 13:12
Show Gist options
  • Save t-yuki/6390719 to your computer and use it in GitHub Desktop.
Save t-yuki/6390719 to your computer and use it in GitHub Desktop.
Example gocov-xml Jenkins job with cobertura plugin for gocov project. You should edit GOROOT and GOPATH and remove `go get xxx`.

Points:

  1. Checkout git repository to subdir src/gocov using Local subdirectory for repo option of Jenkins Git Plugin.
  2. Add Jenkins $WORKSPACE to $GOPATH
  3. Convert gocov output. absolute path to relative path.
mkdir -p $JENKINS_HOME/gopath
export GOROOT=$JENKINS_HOME/workspace/golang
export GOPATH=$JENKINS_HOME/gopath:$WORKSPACE
export PATH=$PATH:$GOROOT/bin:$JENKINS_HOME/gopath/bin
go get -u github.com/axw/gocov/...
go get -u github.com/t-yuki/gocov-xml
gocov test gocov > coverage.json
sed -i -e 's|'$WORKSPACE'/||g' coverage.json
gocov-xml < coverage.json > coverage.xml
<recipe plugin="[email protected]">
<id>com.github.t-yuki.gocov-xml.examples.gocov</id>
<version>1.0</version>
<displayName>Example gocov-xml Jenkins job with cobertura plugin for gocov project.</displayName>
<description></description>
<ingredients>
<job>
<name>gocov</name>
<description></description>
<definition>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.redmine.RedmineProjectProperty plugin="[email protected]">
<projectName></projectName>
<redmineVersionNumber></redmineVersionNumber>
</hudson.plugins.redmine.RedmineProjectProperty>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<name></name>
<refspec></refspec>
<url>https://github.com/axw/gocov.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</name>
</hudson.plugins.git.BranchSpec>
</branches>
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>false</recursiveSubmodules>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<authorOrCommitter>false</authorOrCommitter>
<clean>false</clean>
<wipeOutWorkspace>false</wipeOutWorkspace>
<pruneBranches>false</pruneBranches>
<remotePoll>false</remotePoll>
<ignoreNotifyCommit>false</ignoreNotifyCommit>
<useShallowClone>false</useShallowClone>
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
<gitTool>Default</gitTool>
<submoduleCfg class="list"/>
<relativeTargetDir>src/gocov</relativeTargetDir>
<reference></reference>
<excludedRegions></excludedRegions>
<excludedUsers></excludedUsers>
<gitConfigName></gitConfigName>
<gitConfigEmail></gitConfigEmail>
<skipTag>false</skipTag>
<includedRegions></includedRegions>
<scmName></scmName>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>mkdir -p $JENKINS_HOME/gopath
export GOROOT=$JENKINS_HOME/workspace/golang
export GOPATH=$JENKINS_HOME/gopath:$WORKSPACE
export PATH=$PATH:$GOROOT/bin:$JENKINS_HOME/gopath/bin
go get -u github.com/axw/gocov/...
go get -u github.com/t-yuki/gocov-xml
gocov test gocov &gt; coverage.json
sed -i -e &apos;s|&apos;$WORKSPACE&apos;/||g&apos; coverage.json
gocov-xml &lt; coverage.json &gt; coverage.xml
</command>
</hudson.tasks.Shell>
</builders>
<publishers>
<hudson.plugins.cobertura.CoberturaPublisher plugin="[email protected]">
<coberturaReportFile>coverage.xml</coberturaReportFile>
<onlyStable>false</onlyStable>
<failUnhealthy>false</failUnhealthy>
<failUnstable>false</failUnstable>
<autoUpdateHealth>false</autoUpdateHealth>
<autoUpdateStability>false</autoUpdateStability>
<zoomCoverageChart>false</zoomCoverageChart>
<maxNumberOfBuilds>0</maxNumberOfBuilds>
<failNoReports>true</failNoReports>
<healthyTarget>
<targets class="enum-map" enum-type="hudson.plugins.cobertura.targets.CoverageMetric">
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>METHOD</hudson.plugins.cobertura.targets.CoverageMetric>
<int>8000000</int>
</entry>
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>LINE</hudson.plugins.cobertura.targets.CoverageMetric>
<int>8000000</int>
</entry>
</targets>
</healthyTarget>
<unhealthyTarget>
<targets class="enum-map" enum-type="hudson.plugins.cobertura.targets.CoverageMetric">
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>METHOD</hudson.plugins.cobertura.targets.CoverageMetric>
<int>0</int>
</entry>
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>LINE</hudson.plugins.cobertura.targets.CoverageMetric>
<int>0</int>
</entry>
</targets>
</unhealthyTarget>
<failingTarget>
<targets class="enum-map" enum-type="hudson.plugins.cobertura.targets.CoverageMetric">
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>METHOD</hudson.plugins.cobertura.targets.CoverageMetric>
<int>0</int>
</entry>
<entry>
<hudson.plugins.cobertura.targets.CoverageMetric>LINE</hudson.plugins.cobertura.targets.CoverageMetric>
<int>0</int>
</entry>
</targets>
</failingTarget>
<sourceEncoding>UTF_8</sourceEncoding>
</hudson.plugins.cobertura.CoberturaPublisher>
</publishers>
<buildWrappers/>
</project>
</definition>
</job>
</ingredients>
</recipe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment