Skip to content

Commit

Permalink
chore: Added Jenkins job to remove retire user files from S3
Browse files Browse the repository at this point in the history
  • Loading branch information
syedimranhassan committed Jan 10, 2025
1 parent f7def03 commit 1316426
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
74 changes: 74 additions & 0 deletions devops/jobs/CheckRetireUser.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package devops.jobs
import static org.edx.jenkins.dsl.Constants.common_wrappers

class CheckRetireUsers {
public static def job = { dslFactory, extraVars ->
assert extraVars.containsKey("DEPLOYMENTS") : "Please define DEPLOYMENTS. It should be list of strings."
assert extraVars.containsKey("IGNORE_LIST") : "Please define IGNORE_LIST. It should be list of strings."
assert !(extraVars.get("DEPLOYMENTS") instanceof String) : "Make sure DEPLOYMENTS is a list of string"

extraVars.get('DEPLOYMENTS').each { deployment , configuration ->
configuration.environments.each { environment ->


dslFactory.job(extraVars.get("FOLDER_NAME","Monitoring") + "/check-retire-users-for-${deployment}") {
parameters {
stringParam('CONFIGURATION_REPO', 'https://github.com/edx/configuration.git')
stringParam('CONFIGURATION_BRANCH', 'master')
}

wrappers common_wrappers

wrappers {
credentialsBinding {
usernamePassword("USERNAME", "PASSWORD", "${deployment}-users-retire-credentials")
def variable = "${deployment}-check-retire-users"
string("ROLE_ARN", variable)
}
}

def rdsignore = ""
extraVars.get('IGNORE_LIST').each { ignore ->
rdsignore = "${rdsignore}-i ${ignore} "
}

def whitelistregions = ""
configuration.REGION_LIST.each { include ->
whitelistregions = "${whitelistregions}-r ${include} "
}

environmentVariables {
env('ENVIRONMENT', environment)
env('DEPLOYMENT', deployment)
env('AWS_DEFAULT_REGION', extraVars.get('REGION'))
env('RDSIGNORE', rdsignore)
env('WHITELISTREGIONS', whitelistregions)
}

multiscm {
git {
remote {
url('$CONFIGURATION_REPO')
branch('$CONFIGURATION_BRANCH')
}
extensions {
cleanAfterCheckout()
pruneBranches()
relativeTargetDirectory('configuration')
}
}
}
steps {
shell(dslFactory.readFileFromWorkspace('devops/resources/check_retire_users.sh'))

}

publishers {
mailer(extraVars.get('NOTIFY_ON_FAILURE'), false, false)

}
}
}
}
}
}
29 changes: 29 additions & 0 deletions devops/resources/check_retire_users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set +u
. /edx/var/jenkins/jobvenvs/virtualenv_tools.sh
# creates a venv with its location stored in variable "venvpath"
create_virtualenv --python=python3.8 --clear
. "$venvpath/bin/activate"
set -u

cd $WORKSPACE/configuration/util/jenkins/remove_retire_user_s3_files

pip install -r requirements.txt
. ../assume-role.sh

# Assume role for different envs
set +x
assume-role ${ROLE_ARN}
set -x

# Set RDSIGNORE if not set in job, need because we're setting -u
# Otherwise we get an error "RDSIGNORE: unbound variable"
if [[ ! -v RDSIGNORE ]]; then
RDSIGNORE=""
fi
if [[ ! -v WHITELISTREGIONS ]]; then
WHITELISTREGIONS=""
fi

python ./remove_retire_user_s3_files.py --environment ${ENVIRONMENT} --deploy ${DEPLOYMENT} --region $AWS_DEFAULT_REGION

0 comments on commit 1316426

Please sign in to comment.