#onenote# jenkins + nexus

How to Start, Stop or Restart your Instance

URL

http://<jenkins.server>/restart
http://<jenkins.server>/safeRestart
http://<jenkins.server>/exit
http://<jenkins.server>/safeExit
http://<jenkins.server>/quietDown
http://<jenkins.server>/cancelQuietDown

Remote API

URL can be invoked by a Remote API.

Using wget:

$ wget –user=<user> –password=<password> http://<jenkins.server>/restart
$ wget –user=<user> –password=<password>
http://<jenkins.server>/safeRestart
$ wget –user=<user> –password=<password>
http://<jenkins.server>/exit
$ wget –user=<user> –password=<password>
http://<jenkins.server>/safeExit
$ wget –user=<user> –password=<password>
http://<jenkins.server>/quietDown
$ wget –user=<user> –password=<password>
http://<jenkins.server>/cancelQuietDown

Using cURL:

$ curl -X POST -u <user>:<password> http://<jenkins.server>/restart
$ curl -X POST -u <user>:<password>
http://<jenkins.server>/safeRestart
$ curl -X POST -u <user>:<password>
http://<jenkins.server>/exit
$ curl -X POST -u <user>:<password>
http://<jenkins.server>/safeExit
$ curl -X POST -u <user>:<password>
http://<jenkins.server>/quietDown
$ curl -X POST -u <user>:<password>
http://<jenkins.server>/cancelQuietDown

Jenkins CLI:

$ java -jar jenkins-cli.jar -s http://<jenkins-server>/ restart
$ java -jar jenkins-cli.jar -s
http://<jenkins-server>/ safe-restart
$ java -jar jenkins-cli.jar -s
http://<jenkins-server>/ shutdown
$ java -jar jenkins-cli.jar -s
http://<jenkins-server>/ safe-shutdown
$ java -jar jenkins-cli.jar -s
http://<jenkins-server>/ quiet-down
$ java -jar jenkins-cli.jar -s
http://<jenkins-server>/ cancel-quiet-down

System Administration

It is obviously possible to administrate the Jenkins process itself. This is the case, for example, when a machine needs to be restarted or upgraded. It is worth to mention that quiet-down is not available in that case. Only user with the required system permissions should be able to run the following commands.

Unix-based

You installed Jenkins on a Debian-based or a Fedora-based distribution, you can use the following commands:

$ sudo service jenkins restart
$ sudo service jenkins stop
$ sudo service jenkins start

From <https://support.cloudbees.com/hc/en-us/articles/216118748-How-to-Start-Stop-or-Restart-your-Instance>

Tag code version by jenkins

  1. Add this config in pom.xml

<scm>
<url>https://stash.hk.xxxx/projects/xxx/</url&gt;
<connection>scm:git:ssh://git@stash.hk.xxx:8203/xxxx.git</connection>
</scm>
<!– start of  https://axelfontaine.com/blog/final-nail.html –>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>versions-maven-plugin</artifactId>

<version>2.1</version>

</plugin>

<plugin>

<artifactId>maven-scm-plugin</artifactId>

<version>1.8.1</version>

<configuration>

<tag>${project.artifactId}-${project.version}</tag>

</configuration>

</plugin>

<!– end of  https://axelfontaine.com/blog/final-nail.html –>

</plugins>

 

  1. Run this command in jenkins

mvn “scm:tag”

 

Nexus

 

http://stackoverflow.com/questions/30107970/how-to-run-mvn-if-there-is-no-maven-installed-on-the-target-machine

– name: Download artifacts from Maven repositories

hosts: localhost

tasks:

– name: copy artifact

shell: mvn org.apache.maven.plugins:maven-dependency-plugin:get -Dartifact=com.xxxx.gbm.aaa.appgrid:aaa-AppGrid-AEM:0.0.21.0-SNAPSHOT:jar -Ddest=test4.jar
upload

mvn deploy:deploy-file -DgroupId=com.xxxx.gbm.aaa.appgrid -DartifactId=aaa-AppGrid-Utility -Dversion=0.0.23.0-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -DrepositoryId=dsnexus-snapshots -Durl=https://dsnexus.uk.hibm.xxxx:8081/nexus/content/repositories/snapshots -Dfile=aaa-AppGrid-Utility-0.0.23.0-SNAPSHOT.jar

 

1. enable pull-request build and check quality in jenkins
1.0 add jacoco plugin in maven
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>

<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>

<configuration>
<rules/>
</configuration>

</plugin>
1.1 branch to build: origin/pr/${pullRequestId}/from
1.2 post-build actions: record JaCoCo coverage report

 

 

jenkins pipeline

def mvn(command) {
withMaven(jdk: ‘JavaSdk8’, maven: ‘maven’, mavenLocalRepo: ”, mavenOpts: ”, mavenSettingsFilePath: ”) {
sh “mvn -f ${pathToPom} ${command}”
}
}

node {

//Jenkins tools
tool name: ‘Default’, type: ‘hudson.plugins.git.GitTool’
tool name: ‘maven’, type: ‘hudson.tasks.Maven$MavenInstallation’
tool name: ‘JavaSdk8’, type: ‘hudson.model.JDK’

stage (‘prepare’) {
checkout([$class: ‘GitSCM’, branches: [[name: “*/${revision}”]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: ‘git’, submoduleCfg: [], userRemoteConfigs: [[url: “${repositoryUrl}”]]])
}

stage (‘set version’) {
mvn “versions:set -DnewVersion=${versionNumber}”
}

stage (‘build + test + deploy’) {
mvn ‘deploy’
}

stage (‘tag git version’) {
mvn “scm:tag”
}

stage (‘prepare release notes’){
sh “curl -G ‘http://pparunner.kh.xxx/sametime-bot-proxy/build&#8217; –data-urlencode ‘room=FSA-BIGDATA-DEV’ –data-urlencode ‘user=Jenkins’ –data-urlencode ‘status=:NEW RELEASE VERSION for {${projectName}} project was deployed to Nexus with release notes: {${releaseNotes}}'”

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s