Памятка по подключению Jenkins
brew install jenkins-lts
brew services start jenkins-lts
cat /Users/markguranov/.jenkins/secrets/initialAdminPassword
####(Т.к. Webhook нельзя делать на локальный хост)
./ngrok http 8080
FROM alpine:3.10.3 as packager
RUN apk --no-cache add openjdk11-jdk openjdk11-jmods
ENV JAVA_MINIMAL="/opt/java-minimal"
# build minimal JRE
RUN /usr/lib/jvm/java-11-openjdk/bin/jlink \
--verbose \
--add-modules \
java.base,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument \
--compress 2 --strip-debug --no-header-files --no-man-pages \
--release-info="add:IMPLEMENTOR=radistao:IMPLEMENTOR_VERSION=radistao_JRE" \
--output "$JAVA_MINIMAL"
FROM alpine:3.10.3
LABEL maintainer="Mark Gurianov [email protected]"
ENV JAVA_HOME=/opt/java-minimal
ENV PATH="$PATH:$JAVA_HOME/bin"
COPY --from=packager "$JAVA_HOME" "$JAVA_HOME"
COPY /target/*.jar app.jar
EXPOSE 8085
ENTRYPOINT ["java","-jar","/app.jar"]
pipeline {
agent any
options {
skipStagesAfterUnstable()
}
environment {
DOCKERHUB_CREDENTIALS = credentials('jenkins.dockerhub')
IMAGE_BASE = 'markstav/jenkins-ci-cd-project'
IMAGE_TAG = "v$BUILD_NUMBER"
IMAGE_NAME = "${env.IMAGE_BASE}:${env.IMAGE_TAG}"
IMAGE_NAME_LATEST = "${env.IMAGE_BASE}:latest"
DOCKERFILE_NAME = "Dockerfile-packaged"
}
stages {
stage('CloneGitRepo') {
agent any
steps {
git credentialsId: '32647e76-60a3-42e4-a5f1-a0d6c5d4fa53', url: 'https://github.com/Mark1708/hello-world-spring-app-with-jenkins.git'
}
}
stage('MavenCompile') {
agent any
steps {
sh './mvnw compile'
}
}
stage('MavenTest') {
agent any
steps {
sh './mvnw test'
}
}
stage('MavenPackage') {
agent any
steps {
sh './mvnw package'
}
}
stage('BuildImage') {
agent any
steps {
sh 'docker build -t $IMAGE_NAME -f Dockerfile-packaged .'
sh 'docker tag $IMAGE_NAME $IMAGE_NAME_LATEST'
}
}
stage('LoginDockerhub') {
agent any
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('PushImage') {
agent any
steps {
sh 'docker push $IMAGE_NAME'
sh 'docker push $IMAGE_NAME_LATEST'
sh "docker rmi ${env.IMAGE_NAME} ${env.IMAGE_NAME_LATEST}"
}
}
stage('Deploy') {
agent any
steps {
echo 'Deploy to cloud'
}
}
}
post {
always {
sh 'docker logout'
}
}
}
Отправляемся сюда, чтобы сгенерить безопасный способ аутентификации
- Java - version 11
- Spring Boot - version 2.7.2
- PostgreSQL
- Flyway
- Docker
- Jenkins
Проект закончен
Проект сделан в образовательных целях
Created by Gurianov Mark - feel free to contact me!