-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from romancin/develop
Develop
- Loading branch information
Showing
3 changed files
with
81 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,80 @@ | ||
pipeline { | ||
environment { | ||
registry = "romancin/tinymediamanager" | ||
repository = "tinymediamanager" | ||
withCredentials = 'dockerhub' | ||
registryCredential = 'dockerhub' | ||
} | ||
agent any | ||
stages { | ||
stage('Cloning Git Repository') { | ||
steps { | ||
git url: 'https://github.com/romancin/tinymediamanager-docker.git', | ||
branch: '$BRANCH_NAME' | ||
} | ||
} | ||
stage('Building image and pushing it to the registry (develop)') { | ||
when{ | ||
branch 'develop' | ||
} | ||
steps { | ||
script { | ||
def gitbranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() | ||
def version = readFile('VERSION') | ||
def versions = version.split('\\.') | ||
def major = gitbranch + '-' + versions[0] | ||
def minor = gitbranch + '-' + versions[0] + '.' + versions[1] | ||
def patch = gitbranch + '-' + version.trim() | ||
docker.withRegistry('', registryCredential) { | ||
def image = docker.build("$registry:$gitbranch", "-f Dockerfile .") | ||
image.push() | ||
image.push(major) | ||
image.push(minor) | ||
image.push(patch) | ||
} | ||
} | ||
} | ||
} | ||
stage('Building image and pushing it to the registry (master)') { | ||
when{ | ||
branch 'master' | ||
} | ||
steps { | ||
script { | ||
def version = readFile('VERSION') | ||
def versions = version.split('\\.') | ||
def major = versions[0] | ||
def minor = versions[0] + '.' + versions[1] | ||
def patch = version.trim() | ||
docker.withRegistry('', registryCredential) { | ||
def image = docker.build("$registry:latest", "-f Dockerfile .") | ||
image.push() | ||
image.push(major) | ||
image.push(minor) | ||
image.push(patch) | ||
} | ||
} | ||
script { | ||
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) { | ||
docker.image('sheogorath/readme-to-dockerhub').run('-v $PWD:/data -e DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME -e DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD -e DOCKERHUB_REPO_NAME=$repository') | ||
registry="romancin/tinymediamanager" | ||
|
||
podTemplate(label: 'github-docker-builder', cloud: 'kubernetes', | ||
containers: [ | ||
containerTemplate(name: 'buildkit', image: 'moby/buildkit:master', ttyEnabled: true, privileged: true), | ||
containerTemplate(name: 'docker-readme', image: 'sheogorath/readme-to-dockerhub', command: 'sleep', args: '99d'), | ||
], | ||
volumes: [ | ||
secretVolume(secretName: 'docker-config', mountPath: '/root/.docker') | ||
]) { | ||
node('github-docker-builder') { | ||
stage('Cloning Git Repository') { | ||
container('buildkit') { | ||
git url: 'https://github.com/romancin/tinymediamanager-docker.git', | ||
branch: '$BRANCH_NAME' | ||
} | ||
} | ||
stage('Building image and pushing it to the registry (develop)') { | ||
if (env.BRANCH_NAME == 'develop') { | ||
def gitbranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() | ||
def version = readFile('VERSION') | ||
def versions = version.split('\\.') | ||
def major = gitbranch + '-' + versions[0] | ||
def minor = gitbranch + '-' + versions[0] + '.' + versions[1] | ||
def patch = gitbranch + '-' + version.trim() | ||
container('buildkit') { | ||
sh """ | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${gitbranch}-v3,push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${major},push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${minor},push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${patch},push=true | ||
""" | ||
} | ||
} | ||
} | ||
stage('Building image and pushing it to the registry (main)') { | ||
if (env.BRANCH_NAME == 'main') { | ||
def gitbranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() | ||
def version = readFile('VERSION') | ||
def versions = version.split('\\.') | ||
def major = versions[0] | ||
def minor = versions[0] + '.' + versions[1] | ||
def patch = version.trim() | ||
container('buildkit') { | ||
sh """ | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:latest-v3,push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${major},push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${minor},push=true | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${patch},push=true | ||
""" | ||
} | ||
container('docker-readme') { | ||
withEnv(['DOCKERHUB_REPO_NAME=tinymediamanager']) { | ||
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) { | ||
sh """ | ||
export DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME} | ||
export DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD} | ||
rm -rf /data && ln -s `pwd` /data | ||
cd /data && node --unhandled-rejections=strict /app/index.js | ||
""" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
stage('Notify Build Result') { | ||
withCredentials([string(credentialsId: 'discord-webhook-notificaciones', variable: 'DISCORD_WEBHOOK')]) { | ||
discordSend description: "[Jenkins] - Pipeline CI-docker-tinymediamanager", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: JOB_NAME, webhookURL: "${DISCORD_WEBHOOK}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
success { | ||
telegramSend(message: '[Jenkins] - Pipeline CI-tinymediamanager-docker $BUILD_URL finalizado con estado :: $BUILD_STATUS', chatId: -395961814) } | ||
} | ||
} | ||
} | ||
} | ||
|
||
properties([[ | ||
$class: 'BuildDiscarderProperty', | ||
strategy: [ | ||
$class: 'LogRotator', | ||
artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10'] | ||
] | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v3.1.16 | ||
v3.1.17 |