From 60326fcd26983206126b371b0e78eb56d0c0c92c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 9 Nov 2022 11:44:26 +0400 Subject: [PATCH] fix jenkinsfile --- Jenkinsfile | 81 +++---------------- .../java/ru/ulstu/ExampleWebApplication.java | 18 +++++ .../configuration/ApplicationProperties.java | 20 +++++ src/main/resources/application.properties | 1 + 4 files changed, 52 insertions(+), 68 deletions(-) create mode 100644 src/main/java/ru/ulstu/configuration/ApplicationProperties.java diff --git a/Jenkinsfile b/Jenkinsfile index 13bbea2..aa09ef6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,75 +1,20 @@ -// node { -// def app -// -// stage('Clone repository') { -// checkout scm -// } -// -// stage('Build image') { -// app = docker.build("romanov73/is:ng-tracker-container-11") -// } -// -// stage('Test image') { -// sh ./gradlew bootRun -Dng-tracker.check-run=true -// app.inside { -// sh 'echo "Tests passed"' -// } -// } -// } -// -// pipeline { -// agent none stages { -// stage('Maven Install') { -// agent { -// docker { -// image 'romanov73/is:ng-tracker-container-11' -// } -// } -// steps { -// sh 'sh ./gradlew bootRun -Dng-tracker.check-run=true' -// } -// } -// stage('Docker Build') { -// agent any -// steps { -// sh 'docker build -t shanem/spring-petclinic:latest .' -// } -// } -// } -// } - pipeline { - /*agent any + agent { + docker { + image 'romanov73/is:ng-tracker-container-11' + } + } stages { stage('Cloning Git') { + steps { + git([url: 'https://git.athene.tech/romanov73/example-web.git', branch: 'master']) + } + } + stage('Test') { steps { - git([url: 'https://git.athene.tech/romanov73/example-web.git', branch: 'master']) + sh 'java -version' + sh 'bash ./gradlew bootRun -Dexample-web.check-run=true' } } - stage('Build') { - steps{ - script { - docker.image('romanov73/is:ng-tracker-container-11').inside { - sh 'bash ./gradlew test' - } - } - }*/ - - agent { docker { image 'romanov73/is:ng-tracker-container-11' } } - stages { - stage('Cloning Git') { - steps { - git([url: 'https://gitlab.com/romanov73/ng-tracker.git', branch: 'master']) - } - } - stage('Test') { - steps { - sh 'java -version' - sh 'bash ./gradlew bootRun -Dng-tracker.check-run=true' - } - } - } - //} - // } - // } + } } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/ExampleWebApplication.java b/src/main/java/ru/ulstu/ExampleWebApplication.java index 5c56791..9c86caa 100644 --- a/src/main/java/ru/ulstu/ExampleWebApplication.java +++ b/src/main/java/ru/ulstu/ExampleWebApplication.java @@ -2,12 +2,30 @@ package ru.ulstu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.event.EventListener; +import ru.ulstu.configuration.ApplicationProperties; @SpringBootApplication @EnableConfigurationProperties public class ExampleWebApplication { + private final ApplicationProperties applicationProperties; + + public ExampleWebApplication(ApplicationProperties applicationProperties) { + this.applicationProperties = applicationProperties; + } + public static void main(String[] args) { SpringApplication.run(ExampleWebApplication.class, args); } + + @EventListener(ApplicationReadyEvent.class) + public void doSomethingAfterStartup() { + System.out.println(applicationProperties.isCheckRun()); + if (applicationProperties.isCheckRun()) { + System.exit(0); + } + } + } diff --git a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java new file mode 100644 index 0000000..d2724de --- /dev/null +++ b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java @@ -0,0 +1,20 @@ +package ru.ulstu.configuration; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +@Component +@ConfigurationProperties(prefix = "example-web") +@Validated +public class ApplicationProperties { + private boolean checkRun; + + public boolean isCheckRun() { + return checkRun; + } + + public void setCheckRun(boolean checkRun) { + this.checkRun = checkRun; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b251eab..819cec4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,3 @@ spring.main.banner-mode=off server.port=8080 +example-web.check-run=false \ No newline at end of file