1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gradle-ssh-pluginでSSH

1
Last updated at Posted at 2019-10-29

gradleに仕事をさせすぎてbuild.gradleが魔境化している昨今、デプロイとかそういうのもお前やっとけよとgradleに押し付けてみましょ。

ということで差し当たり今回はjacocoのカバレッジレポートをサーバーに放り込んででgradleくん。おら、さっさと働くんだよ。

build.gralde
buildscript {
	repositories {
	  jcenter()
	}
	dependencies {
	  classpath 'org.hidetake:gradle-ssh-plugin:2.10.1'
	}
}

apply plugin: 'org.hidetake.ssh'

remotes {
	coverageCenter {
		host = coverageCenterHost
		user = coverageCenterUser
		// この辺のパスなんかいい取り方がありそうなんだが
		identity = file(System.getProperty("user.home") + '/.ssh/id_rsa')
		// パスワード認証の場合はidentityと代えてこっちを
		// password = 'hogehoge'
	}
}

task publish(dependsOn: 'jacoco') {
	// リモートのパス
	def uploadDir = "/usr/share/nginx/html/$project.name"
	def localDir = "$buildDir/reports/jacoco/jacoco"
	ssh.run {
		session(remotes.coverageCenter) {
			// コマンドの実行
			execute "mkdir -p $uploadDir" 
			// フォルダコピー
			put from:localDir, into:uploadDir
		}
	}
}

一応ホスト名なんかはgradle.propertyから取るようにしたが、build.gradleに直書きしてもよろしいざんす。

gradle.properties
coverageCenterHost = 192.168.99.100
coverageCenterUser = user

ビルドする前にバージョン差し込んでビルドして単体通してカバレッジレポート作ってリリースノート作って配布物作って部品系はNexusにアップロードしてリリース案内をslackに投稿して評価環境にモジュールをデプロイしてservice restartもちゃんとやれよ。前までのログはzipにしてNASに置いとくんだ。あーそれともう一つ、カバレッジレポートをWEBで公開しとけよ。

さて、他にgradleちゃんにやってもらうお仕事なかったかしら・・・。

あ、Dockerイメージ作らせるべ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?