diff --git a/Dockerfile b/Dockerfile index 8e99f41..aab218d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,11 @@ FROM debian:latest -#RUN apt-key update RUN apt-get update RUN apt-get -y upgrade -RUN apt-get -y install openjdk-8-jre openjdk-8-jdk +RUN apt-get -y install openjdk-8-jre openjdk-8-jdk curl wget WORKDIR /bot_src -ADD . /bot_src/ -RUN chmod +x gradlew +ADD DownloadLast.sh /bot_src/ +RUN chmod +x DownloadLast.sh +RUN ./DownloadLast.sh ENV PORT=8080 ENV TOKEN=10 -RUN ./gradlew build -CMD java -jar build/libs/DiscordBot-0.1.0.jar -t ${TOKEN} +CMD java -jar bot.jar -t ${TOKEN} diff --git a/DownloadLast.sh b/DownloadLast.sh new file mode 100755 index 0000000..d15ecbd --- /dev/null +++ b/DownloadLast.sh @@ -0,0 +1,11 @@ +#!/bin/bash +#This script download the last stable build on jenkins + +data=$(curl -g "https://jenkins.seb6596.ovh/job/Bot%20Discord%20Gradle/lastStableBuild/api/xml?xpath=/freeStyleBuild/artifact&wrapper=artifacts") +relativePath=$(grep -oPm1 "(?<=)[^<]+" <<< "$data") +jarFile=$(grep -oPm1 "(?<=)[^<]+" <<< "$data") +url="https://jenkins.seb6596.ovh/job/Bot%20Discord%20Gradle/lastStableBuild/artifact/"${relativePath} +echo ${url} +wget ${url} -O bot.jar + + diff --git a/Jenkinsfile b/Jenkinsfile index 4c94390..696ca4b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,10 @@ node { def app stage('Clone') { // for display purposes // Get some code from a GitHub repository - git 'https://github.com/BrokenFire/BrokenDiscordBot.git' + git url: 'https://github.com/BrokenFire/BrokenDiscordBot.git', branch: 'devel' + } + stage('Gradle Buil'){ + build job: 'Bot Discord Gradle', wait: true } stage('Build image') { /* This builds the actual image; synonymous to @@ -15,11 +18,10 @@ node { * First, the incremental build number from Jenkins * Second, the 'latest' tag. * Pushing multiple tags is cheap, as all the layers are reused. */ - app.push() + app.push("devel") } stage('Cleaning'){ sh "docker image prune -f" - build job: 'Bot Discord javadoc', wait: false } } diff --git a/build.gradle b/build.gradle index 0983c50..7a30fb9 100644 --- a/build.gradle +++ b/build.gradle @@ -8,14 +8,32 @@ buildscript { } } +apply plugin: 'base' apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'org.springframework.boot' + +def versionObj = new Version(major: 0, minor: 2, revision: 0) + +group = "net.broken" +archivesBaseName = "BrokenDiscordBot" +version = "$versionObj" + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + + + +jar.doFirst { + delete "${buildDir}/libs/*" +} + jar { + baseName = 'DiscordBot' - version = '0.1.0' + } repositories { @@ -28,8 +46,6 @@ javadoc { classpath = configurations.compile } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 dependencies { compile("org.springframework.boot:spring-boot-starter-web"){ @@ -56,3 +72,15 @@ dependencies { } } +class Version { + String major, minor, revision + + static String getBuild() { + System.getenv("BUILD_NUMBER") ?: System.getProperty("BUILD_NUMBER") ?: + System.getenv("GIT_COMMIT")?.substring(0, 7) ?: System.getProperty("GIT_COMMIT")?.substring(0, 7) ?:"DEV" + } + + String toString() { + "${major}.${minor}.${revision}_$build" + } +} \ No newline at end of file