Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jan 27, 2018
1 parent 120ee1b commit 5ccb8b5
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 75 deletions.
69 changes: 69 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,75 @@ Changelog of Violation Comments to Bitbucket Server Plugin.
## Unreleased
### No issue

**Doc**


[6f886c350391fca](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/6f886c350391fca) Tomas Bjerre *2018-01-27 18:25:25*

**Formatting**


[32a070215959c69](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/32a070215959c69) Joseph Petersen *2018-01-25 07:18:04*

**Provide descriptors and config jelly**

* Begin work on deprecated password

[ac7ee1d0ac3e013](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/ac7ee1d0ac3e013) Joseph *2018-01-25 07:12:12*

**Fix upperbound requirement due to parent POM upgrade**


[82c791dfac4fb09](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/82c791dfac4fb09) Joseph *2018-01-25 07:12:12*

**One too many extension**


[794b26ab74ce4ef](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/794b26ab74ce4ef) Joseph *2018-01-25 07:12:12*

**Delete button**


[6121212b8c5134c](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/6121212b8c5134c) Joseph *2018-01-25 07:12:12*

**Migrate to credentials**


[5438932ae8da3a3](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/5438932ae8da3a3) Joseph *2018-01-25 07:12:12*

**Update and cleanup POM**


[2a919e623566d04](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/2a919e623566d04) Joseph *2018-01-25 07:12:12*

**cleanup dead code**


[037e30e6268e71b](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/037e30e6268e71b) Joseph *2018-01-25 07:12:12*

**Update Jenkinsfile**


[d54f6eb2cfbe9aa](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/d54f6eb2cfbe9aa) Joseph Petersen *2018-01-24 21:33:31*

**Give it a symbol and extension**


[811b69be0183ca2](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/811b69be0183ca2) Joseph *2018-01-24 15:31:14*


## 1.64
### No issue

**Google error-prone**


[187c30137e46d29](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/187c30137e46d29) Tomas Bjerre *2018-01-14 11:59:05*


## 1.63
### No issue

**Relocating to correct Java identifier**


Expand Down
101 changes: 32 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,17 @@ The pull request will be commented like this.

Available in Jenkins [here](https://wiki.jenkins-ci.org/display/JENKINS/Violation+Comments+to+Bitbucket+Server+Plugin).

## Example use case
Here is an example use case where a pull request is triggered from Bitbucket Server, merged, checked and comments added to pull request in Bitbucket Server.

You may also use it for an ordinary build job, to simply comment the commit that was built.

### Notify Jenkins from Bitbucket Server
You can use [Generic Webhook Trigger plugin](https://github.com/tomasbjerre/generic-webhook-trigger-plugin) to get the variables you need.

You may also use [Pull Request Notifier for Bitbucket Server](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket) to trigger a Jenkins build from an event in Bitbucket Server. It can supply any parameters and variables you may need. Here is an example URL.

```
http://localhost:8080/jenkins/job/builder/buildWithParameters?FROM=${PULL_REQUEST_FROM_HASH}&TO=${PULL_REQUEST_TO_HASH}&TOSLUG=${PULL_REQUEST_TO_REPO_SLUG}&TOREPO=${PULL_REQUEST_TO_HTTP_CLONE_URL}&FROMREPO=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&ID=${PULL_REQUEST_ID}&PROJECT=${PULL_REQUEST_TO_REPO_PROJECT_KEY}
```
* You may trigger with a [webhook](https://confluence.atlassian.com/bitbucketserver/managing-webhooks-in-bitbucket-server-938025878.html) in Bitbucket Server. And consume it with [Generic Webhook Trigger plugin](https://github.com/tomasbjerre/generic-webhook-trigger-plugin) to get the variables you need.

### Jenkins job
The Jenkins job may perform the merge, and run any checkers on it, with a shell script build step. It needs to be a parameterized build. To match URL in example above, these parameters are needed.
* ID
* TO
* TOSLUG
* TOREPO
* FROM
* FROMREPO
* PROJECT
* Or, trigger with [Pull Request Notifier for Bitbucket Server](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket). It can supply any parameters and variables you may need. Here is an example URL. `http://localhost:8080/jenkins/job/builder/buildWithParameters?FROM=${PULL_REQUEST_FROM_HASH}&TO=${PULL_REQUEST_TO_HASH}&TOSLUG=${PULL_REQUEST_TO_REPO_SLUG}&TOREPO=${PULL_REQUEST_TO_HTTP_CLONE_URL}&FROMREPO=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&ID=${PULL_REQUEST_ID}&PROJECT=${PULL_REQUEST_TO_REPO_PROJECT_KEY}`

The shell script may look like this.
*You must perform the merge before build*. If you don't perform the merge, the reported violations will refer to other lines then those in the pull request. The merge can be done with a shell script like this.

```
echo ---
echo --- Mergar from $FROM in $FROMREPO to $TO in $TOREPO
echo --- Merging from $FROM in $FROMREPO to $TO in $TOREPO
echo ---
git clone $TOREPO
cd *
Expand All @@ -98,15 +80,9 @@ git fetch from
git merge $FROM
git --no-pager log --max-count=10 --graph --abbrev-commit
your build command here!
Your build command here!
```

### Configure plugin
This plugin may be added as a post build step to analyze the workspace and report comments back to pull request in Bitbucket Server. [Here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-config.png) is an example of how that may look like.

### The result
And finally [here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-stash.png) is an example Bitbucket Server comment.

## Job DSL Plugin

This plugin can be used with the Job DSL Plugin. Here is an example.
Expand Down Expand Up @@ -204,12 +180,7 @@ git --no-pager log --max-count=10 --graph --abbrev-commit
repoSlug("\$PULL_REQUEST_TO_REPO_SLUG")
pullRequestId("\$PULL_REQUEST_ID")
useUsernamePasswordCredentials(false)
usernamePasswordCredentialsId(null)
useUsernamePassword(true)
username("admin")
password("admin")
usernamePasswordCredentialsId('bitbucketservercredentials')
minSeverity('INFO')
createSingleFileComments(true)
Expand Down Expand Up @@ -242,40 +213,38 @@ This plugin can be used with the Pipeline Plugin:

```
node {
def mvnHome = tool 'Maven 3.3.9'
deleteDir()
stage('Merge') {
sh "git init"
sh "git fetch --no-tags --progress git@git:group/reponame.git +refs/heads/*:refs/remotes/origin/* --depth=200"
sh "git checkout origin/${env.targetBranch}"
sh "git merge origin/${env.sourceBranch}"
sh "git log --graph --abbrev-commit --max-count=10"
sh '''
git clone [email protected]:tomasbjerre/violations-test.git .
git checkout master
git merge origin/feature/addingcrap
'''
}
stage('Build') {
sh '''
./build.sh || ls
'''
}
stage('Static code analysis') {
sh "${mvnHome}/bin/mvn package -DskipTests -Dmaven.test.failure.ignore=false -Dsurefire.skip=true -Dmaven.compile.fork=true -Dmaven.javadoc.skip=true"
step([
$class: 'ViolationsToBitbucketServerRecorder',
config: [
bitbucketServerUrl: 'http://localhost:7990/bitbucket',
createCommentWithAllSingleFileComments: false,
createSingleFileComments: true,
projectKey: 'PROJECT_1',
repoSlug: 'rep_1',
pullRequestId: '1',
useUsernamePassword: true,
username: 'admin',
password: 'admin',
useUsernamePasswordCredentials: false,
minSeverity: 'INFO',
keepOldComments: false,
violationConfigs: [
[ pattern: '.*/checkstyle-result\\.xml$', parser: 'CHECKSTYLE', reporter: 'Checkstyle' ],
[ pattern: '.*/findbugsXml\\.xml$', parser: 'FINDBUGS', reporter: 'Findbugs' ],
[ pattern: '.*/pmd\\.xml$', parser: 'PMD', reporter: 'PMD' ],
]
ViolationsToBitbucketServer([
bitbucketServerUrl: 'http://localhost:7990/',
commentOnlyChangedContent: true,
commentOnlyChangedContentContext: 5,
createCommentWithAllSingleFileComments: false,
createSingleFileComments: true,
keepOldComments: true,
projectKey: 'PROJ', // Use environment variable here
pullRequestId: '1', // Use environment variable here
repoSlug: 'violations-test', // Use environment variable here
usernamePasswordCredentialsId: 'bitbucketservercredentials', //Create a Username/Passwords credential with this ID
violationConfigs: [
// Many more formats available, check https://github.com/tomasbjerre/violations-lib
[parser: 'FINDBUGS', pattern: '.*/findbugs/.*\\.xml\$', reporter: 'Findbugs'],
[parser: 'CHECKSTYLE', pattern: '.*/checkstyle/.*\\.xml\$', reporter: 'Checkstyle']
]
])
}
Expand All @@ -285,12 +254,6 @@ node {
## Developer instructions
Instructions for developers.

### Get the code

```
git clone [email protected]:tomasbjerre/violation-comments-to-stash-plugin.git
```

### Plugin development
More details on Jenkins plugin development is available [here](https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial).

Expand Down
2 changes: 1 addition & 1 deletion debug.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
mvnDebug -q hpi:run -Djava.util.logging.config.file=logging.properties
mvnDebug -q hpi:run -Djava.util.logging.config.file=logging.properties -Djenkins.version=2.89.3

2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
mvn -q hpi:run -Djava.util.logging.config.file=logging.properties
mvn -q hpi:run -Djava.util.logging.config.file=logging.properties -Djenkins.version=2.89.3
5 changes: 1 addition & 4 deletions sandbox/violations-test.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ node {
createSingleFileComments: true,
projectKey: 'PROJ',
repoSlug: 'violations-test',
usernamePasswordCredentialsId: 'bitbucketservercredentials'
pullRequestId: '1',
useUsernamePassword: true,
username: 'admin',
password: 'admin',
useUsernamePasswordCredentials: false,
minSeverity: 'INFO',
keepOldComments: false,
violationConfigs: [
Expand Down

0 comments on commit 5ccb8b5

Please sign in to comment.