-
Notifications
You must be signed in to change notification settings - Fork 5
EN-81119: adopt commonPipeline with library #498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sarah-salinas
wants to merge
4
commits into
main
Choose a base branch
from
sarahs/EN-81119/adopt-common-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−292
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| java adoptopenjdk-8.0.265+1 | ||
| sbt 1.9.7 |
This file contains hidden or 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,284 +1,34 @@ | ||
| @Library('socrata-pipeline-library@9.7.0') | ||
| @Library('socrata-pipeline-library@sarahs/sbt-library-publishing') _ | ||
|
|
||
| import com.socrata.ReleaseMetadataService | ||
| def rmsSupportedEnvironment = com.socrata.ReleaseMetadataService.SupportedEnvironment | ||
|
|
||
| // set up service and project variables | ||
| String service = 'data-coordinator' | ||
| String project_wd = 'coordinator' | ||
| boolean isPr = env.CHANGE_ID != null | ||
| boolean isHotfix = isHotfixBranch(env.BRANCH_NAME) | ||
| boolean skip = false | ||
| String lastStage | ||
| boolean publishLibrary = false | ||
|
|
||
| // instanciate libraries | ||
| def sbtbuild = new com.socrata.SBTBuild(steps, service, project_wd) | ||
| def dockerize = new com.socrata.Dockerize(steps, service, BUILD_NUMBER) | ||
| def releaseTag = new com.socrata.ReleaseTag(steps, service) | ||
| def semVerTag = new com.socrata.SemVerTag(steps) | ||
|
|
||
| pipeline { | ||
| options { | ||
| ansiColor('xterm') | ||
| buildDiscarder(logRotator(numToKeepStr: '50')) | ||
| timeout(time: 20, unit: 'MINUTES') | ||
| } | ||
| parameters { | ||
| string(name: 'AGENT', defaultValue: 'build-worker-pg13', description: 'Which build agent to use?') | ||
| string(name: 'BRANCH_SPECIFIER', defaultValue: 'origin/main', description: 'Use this branch for building the artifact.') | ||
| booleanParam(name: 'RELEASE_BUILD', defaultValue: false, description: 'Are we building a release candidate?') | ||
| booleanParam(name: 'RELEASE_DRY_RUN', defaultValue: false, description: 'To test out the release build.') | ||
| string(name: 'RELEASE_NAME', description: 'For release builds, the release name which is used in the git tag and the build id.') | ||
| } | ||
| agent { | ||
| label params.AGENT | ||
| } | ||
| environment { | ||
| SCALA_VERSION = '2.12' | ||
| DEPLOY_PATTERN = "${service}*" | ||
| WEBHOOK_ID = 'WORKFLOW_EGRESS_AUTOMATION' | ||
| } | ||
| stages { | ||
| stage('Check for Version Change') { | ||
| when { | ||
| branch 'main' | ||
| not { expression { params.RELEASE_BUILD } } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| // Checkout to fetch tags because the default checkout does not include tags | ||
| // Fetching the tags without uisng checkout will confuse Jenkins about the git branch | ||
| semVerTag.checkout('main') | ||
| publishLibrary = haveCertainFilesChanged(filePaths: ['version.sbt']) | ||
| } | ||
| } | ||
| } | ||
| stage('Publish Library') { | ||
| when { | ||
| branch 'main' | ||
| not { expression { params.RELEASE_BUILD } } | ||
| expression { publishLibrary } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| skip = true | ||
| semVerTag.checkoutClosestTag() | ||
| // Build & Publish | ||
| sbtbuild.setRunITTest(true) | ||
| sbtbuild.setNoSubproject(true) | ||
| sbtbuild.setScalaVersion(env.SCALA_VERSION) | ||
| sbtbuild.setPublish(true) | ||
| sbtbuild.setBuildType("library") | ||
| sbtbuild.build() | ||
| } | ||
| } | ||
| } | ||
| stage('Hotfix Tag') { | ||
| when { | ||
| expression { isHotfix } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| if (releaseTag.noCommitsOnHotfixBranch(env.BRANCH_NAME)) { | ||
| skip = true | ||
| echo "SKIP: Skipping the rest of the build because there are no commits on the hotfix branch yet" | ||
| } else { | ||
| env.CURRENT_RELEASE_NAME = releaseTag.getReleaseName(env.BRANCH_NAME) | ||
| env.HOTFIX_NAME = releaseTag.getHotfixName(env.CURRENT_RELEASE_NAME) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| stage('Generate Leaked Secrets Report') { | ||
| when { | ||
| not { expression { skip } } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| assert isInstalled('gitleaks'): 'gitleaks is missing.' | ||
| String secretsReportFileName = 'gitleaks-report.json' | ||
| String gitleaksCommand = getGitleaksCommand secretsReportFileName | ||
| assert sh (script: gitleaksCommand, returnStatus: true) == 0: \ | ||
| 'Attempt to run gitleaks failed.' | ||
| echo "Generated report ${secretsReportFileName}." | ||
| archiveArtifacts artifacts: secretsReportFileName, fingerprint: true | ||
| } | ||
| } | ||
| } | ||
| stage('Build') { | ||
| when { | ||
| allOf { | ||
| not { expression { return params.PUBLISH } } | ||
| not { expression { skip } } | ||
| } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| sbtbuild.setRunITTest(true) | ||
| sbtbuild.setNoSubproject(true) | ||
| sbtbuild.setPublish(false) | ||
| sbtbuild.setScalaVersion(env.SCALA_VERSION) | ||
| sbtbuild.setSrcJar("coordinator/target/coordinator-assembly.jar") | ||
| sbtbuild.build() | ||
| } | ||
| } | ||
| } | ||
| stage('Docker Build') { | ||
| when { | ||
| allOf { | ||
| not { expression { isPr } } | ||
| not { expression { skip } } | ||
| not { expression { return params.PUBLISH } } | ||
| } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| if (params.RELEASE_BUILD || isHotfix) { | ||
| env.VERSION = (isHotfix) ? env.HOTFIX_NAME : params.RELEASE_NAME | ||
| env.DOCKER_TAG = dockerize.dockerBuildWithSpecificTag( | ||
| tag: env.VERSION, | ||
| path: sbtbuild.getDockerPath(), | ||
| artifacts: [sbtbuild.getDockerArtifact()] | ||
| ) | ||
| } else { | ||
| env.DOCKER_TAG = dockerize.dockerBuildWithDefaultTag( | ||
| version: 'STAGING', | ||
| sha: env.GIT_COMMIT, | ||
| path: sbtbuild.getDockerPath(), | ||
| artifacts: [sbtbuild.getDockerArtifact()] | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| post { | ||
| success { | ||
| script { | ||
| if (isHotfix || params.RELEASE_BUILD) { | ||
| String version = (isHotfix) ? env.HOTFIX_NAME : params.RELEASE_NAME | ||
| String branchName = (isHotfix) ? env.BRANCH_NAME : params.BRANCH_SPECIFIER | ||
| env.GIT_TAG = releaseTag.createWithCheckout(version, branchName, params.RELEASE_DRY_RUN) | ||
| } | ||
| if (params.RELEASE_BUILD) { | ||
| def releaseHelper = new com.socrata.ReleaseHelper(steps) | ||
| String previousPreviousRelease = releaseHelper.previous( | ||
| releaseHelper.previous( | ||
| releaseHelper.getMostRecentReleaseID() | ||
| ) | ||
| ) | ||
| releaseTag.createHotfixBranch(params.RELEASE_NAME, params.RELEASE_DRY_RUN) | ||
| releaseTag.cleanUpHotfixBranch(previousPreviousRelease, params.RELEASE_DRY_RUN) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| stage('Publish Image') { | ||
| when { | ||
| allOf { | ||
| not { expression { isPr } } | ||
| not { expression { skip } } | ||
| not { expression { return params.PUBLISH } } | ||
| not { expression { return params.RELEASE_BUILD && params.RELEASE_DRY_RUN } } | ||
| } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| if (isHotfix || params.RELEASE_BUILD) { | ||
| env.BUILD_ID = dockerize.publish(sourceTag: env.DOCKER_TAG) | ||
| } else { | ||
| env.BUILD_ID = dockerize.publish( | ||
| sourceTag: env.DOCKER_TAG, | ||
| environments: ['internal'] | ||
| ) | ||
| } | ||
| currentBuild.description = env.BUILD_ID | ||
| } | ||
| } | ||
| post { | ||
| success { | ||
| script { | ||
| if (isHotfix || params.RELEASE_BUILD) { | ||
| env.PURPOSE = (isHotfix) ? 'hotfix' : 'initial' | ||
| env.RELEASE_ID = (isHotfix) ? env.CURRENT_RELEASE_NAME : params.RELEASE_NAME | ||
| Map buildInfo = [ | ||
| "project_id": service, | ||
| "build_id": env.BUILD_ID, | ||
| "release_id": env.RELEASE_ID, | ||
| "git_tag": env.GIT_TAG, | ||
| "purpose": env.PURPOSE, | ||
| ] | ||
| createBuild( | ||
| buildInfo, | ||
| rmsSupportedEnvironment.production | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| stage('Deploy') { | ||
| when { | ||
| not { expression { isPr } } | ||
| not { expression { skip } } | ||
| not { expression { return params.RELEASE_BUILD } } | ||
| not { expression { return params.PUBLISH } } | ||
| } | ||
| steps { | ||
| script { | ||
| lastStage = env.STAGE_NAME | ||
| env.ENVIRONMENT = (isHotfix) ? 'rc' : 'staging' | ||
| marathonDeploy( | ||
| serviceName: env.DEPLOY_PATTERN, | ||
| tag: env.BUILD_ID, | ||
| environment: env.ENVIRONMENT | ||
| ) | ||
| // While working on migrating from marathon to ECS, we are keeping the tagged images up to date | ||
| // Once the migration is done, we will remove the marathonDeploy and leave in place this publish which triggers the ECS deployment | ||
| env.TARGET_DEPLOY_TAG = (env.ENVIRONMENT == 'rc') ? 'rc' : 'latest' | ||
| dockerize.publish( | ||
| sourceTag: env.DOCKER_TAG, | ||
| targetTag: env.TARGET_DEPLOY_TAG, | ||
| environments: ['internal'] | ||
| ) | ||
| } | ||
| } | ||
| post { | ||
| success { | ||
| script { | ||
| if (isHotfix) { | ||
| Map deployInfo = [ | ||
| "build_id": env.BUILD_ID, | ||
| "environment": env.ENVIRONMENT, | ||
| ] | ||
| createDeployment( | ||
| deployInfo, | ||
| rmsSupportedEnvironment.production | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| post { | ||
| failure { | ||
| script { | ||
| boolean buildingMain = (env.JOB_NAME.contains("${service}/main")) | ||
| if (buildingMain) { | ||
| teamsWorkflowMessage( | ||
| message: "[${currentBuild.fullDisplayName}](${env.BUILD_URL}) has failed in stage ${lastStage}", | ||
| workflowCredentialID: WEBHOOK_ID | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| commonPipeline( | ||
| defaultBuildWorker: 'build-worker-pg13', | ||
| jobName: 'data-coordinator', | ||
| language: 'scala', | ||
| languageOptions: [ | ||
| isMultiProjectRepository: true, | ||
| ], | ||
| numberOfBuildsToKeep: 50, | ||
| projects: [ | ||
| [ | ||
| name: 'data-coordinator', | ||
| compiled: true, | ||
| deploymentEcosystem: 'marathon-mesos', | ||
| docker: [ | ||
| buildContext: 'coordinator/docker', | ||
| ], | ||
| marathonInstanceNamePattern: 'data-coordinator*', | ||
| type: 'service', | ||
| ], | ||
| [ | ||
| name: 'coordinator-external', | ||
| compiled: true, | ||
| paths: [ | ||
| buildContext: '.', | ||
| version: 'version.sbt', | ||
| ], | ||
| type: 'library', | ||
| ], | ||
| ], | ||
| teamsChannelWebhookId: 'WORKFLOW_EGRESS_AUTOMATION', | ||
| ) | ||
| // TODO: support sbtbuild.setRunITTest(true) = sbt it:test |
This file contains hidden or 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 hidden or 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,6 +1,6 @@ | ||
| import Dependencies._ | ||
|
|
||
| name := "coordinator" | ||
| name := "data-coordinator" | ||
|
|
||
| libraryDependencies ++= Seq( | ||
| c3po, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| ThisBuild / version := "4.2.46-SNAPSHOT" | ||
| ThisBuild / version := "4.2.50-SNAPSHOT" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incremented more than it should be just to make my testing setup easier.