diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 8d72620..d66d0e4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -5,13 +5,12 @@ tag = True tag_name = {new_version} message = Bump version: {current_version} -> {new_version} -[bumpversion:file:semver.semver] -search = version = {current_version} -replace = version = {new_version} +[bumpversion:file:VERSION] +search = __version__ = {current_version} +replace = __version__ = {new_version} [semver] -main_branches = develops, env-test, env-stage, env-prod -major_branches = -minor_branches = feature, RightBrain-Networks/feature -patch_branches = hotfix, bugfix - +main_branches = development +major_branches = +minor_branches = feature +patch_branches = bugfix, hotfix \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 345abe1..e203846 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,19 +1,30 @@ -library('pipeline-library@feature/add-with-ecr') +library('pipeline-library') pipeline { options { timestamps() } agent any environment { SERVICE = 'kmstool' - GITHUB_KEY = 'Jenkins' - GITHUB_URL = 'https://github.com/dejonghe/kmstool' + GITHUB_KEY = 'kmstoolDeployKey' + GITHUB_URL = 'git@github.com:dejonghe/kmstool.git' DOCKER_REGISTRY = '356438515751.dkr.ecr.us-east-1.amazonaws.com' } stages { stage('Version') { steps { // runs the automatic semver tool which will version, & tag, - runAutoSemver() + withEcr { + runAutoSemver() + } + } + post{ + // Update Git with status of version stage. + success { + updateGithubCommitStatus(GITHUB_URL, 'Passed version stage', 'SUCCESS', 'Version') + } + failure { + updateGithubCommitStatus(GITHUB_URL, 'Failed version stage', 'FAILURE', 'Version') + } } } stage('Build') { @@ -23,9 +34,9 @@ pipeline { echo "Building ${env.SERVICE} docker image" // Docker build flags are set via the getDockerBuildFlags() shared library. - sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${getVersion('-d')} ." + sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.SEMVER_RESOLVED_VERSION} ." - sh "tar -czvf ${env.SERVICE}-${getVersion('-d')}.tar.gz kmstool" + sh "tar -czvf ${env.SERVICE}-${env.SEMVER_RESOLVED_VERSION}.tar.gz kmstool" } post{ // Update Git with status of build stage. @@ -37,27 +48,41 @@ pipeline { } } } - stage('Push') + stage('Ship') { steps { withEcr { - sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:${getVersion('-d')}" + sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.SEMVER_RESOLVED_VERSION}" + script + { + if("${env.BRANCH_NAME}" == "development") + { + sh "docker tag ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.SEMVER_RESOLVED_VERSION} ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" + sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" + } + } } //Copy tar.gz file to s3 bucket - sh "aws s3 cp ${env.SERVICE}-${getVersion('-d')}.tar.gz s3://rbn-ops-pkg-us-east-1/${env.SERVICE}/${env.SERVICE}-${getVersion('-d')}.tar.gz" + sh "aws s3 cp ${env.SERVICE}-${env.SEMVER_RESOLVED_VERSION}.tar.gz s3://rbn-ops-pkg-us-east-1/${env.SERVICE}/${env.SERVICE}-${env.SEMVER_RESOLVED_VERSION}.tar.gz" } post{ // Update Git with status of push stage. success { - updateGithubCommitStatus(GITHUB_URL, 'Passed push stage', 'SUCCESS', 'Push') + updateGithubCommitStatus(GITHUB_URL, 'Passed ship stage', 'SUCCESS', 'Ship') } failure { - updateGithubCommitStatus(GITHUB_URL, 'Failed push stage', 'FAILURE', 'Push') + updateGithubCommitStatus(GITHUB_URL, 'Failed ship stage', 'FAILURE', 'Ship') } } } + stage('Push Version and Tag') { + steps { + echo "The current branch is ${env.BRANCH_NAME}." + gitPush(env.GITHUB_KEY, env.BRANCH_NAME, true) + } + } } post { always { diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..540c233 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +__version__ = 1.4.0 \ No newline at end of file