Skip to content
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

chore: Re-add experiment job resource used by Optimizely job #1747

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions experiments/jobs/BackUpOptimizely.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Pulls current state of experiment code in Optimizely and backs up to git history branch in edx/optimizely-experiments.

Vars consumed for this job:
* FOLDER_NAME: folder
* NOTIFY_ON_FAILURE: [email protected]
* OPTIMIZELY_TOKEN: optimizely api token (required)
* SECURE_GIT_CREDENTIALS: secure-bot-user (required)
* SSH_AGENT_KEY : ssh-credential-name
*/
package experiments.jobs

class BackUpOptimizely {

public static def job = { dslFactory, extraVars ->

dslFactory.job(extraVars.get("FOLDER_NAME","Experiments") + "/back-up-optimizely") {

environmentVariables {
env('GIT_AUTHOR_NAME', extraVars.get('GIT_AUTHOR_NAME'))
env('GIT_AUTHOR_EMAIL', extraVars.get('GIT_AUTHOR_EMAIL'))
env('GIT_COMMITTER_NAME', extraVars.get('GIT_AUTHOR_NAME'))
env('GIT_COMMITTER_EMAIL', extraVars.get('GIT_AUTHOR_EMAIL'))
}

def gitCredentialId = extraVars.get('SECURE_GIT_CREDENTIALS','')

wrappers {
credentialsBinding {
string('OPTIMIZELY_TOKEN', 'optimizely-token')
}
sshAgent(gitCredentialId)
}

multiscm {
git {
remote {
url(extraVars.get('OPTIMIZELY_EXPERIMENTS_REPO'))
branch("history")
if (gitCredentialId) {
credentials(gitCredentialId)
}
}
extensions {
cleanAfterCheckout()
pruneBranches()
relativeTargetDirectory('optimizely-experiments')
}
}
git {
remote {
url("https://github.com/edx/py-opt-cli.git")
branch('master')
}
extensions {
cleanAfterCheckout()
pruneBranches()
relativeTargetDirectory('py-opt-cli')
}
}
}


triggers {
// Trigger every hour
cron("H * * * *")
}

steps {
shell(dslFactory.readFileFromWorkspace("experiments/resources/back_up_optimizely.sh"))
}

// Alert on call revenue engineer on failure.
publishers {
mailer(extraVars.get('NOTIFY_ON_FAILURE'), false, false)
}
}
}

}
41 changes: 41 additions & 0 deletions experiments/resources/back_up_optimizely.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -exuo pipefail

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

# Required by click http://click.pocoo.org/5/python3/
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export GIT_AUTHOR_NAME
export GIT_AUTHOR_EMAIL
export GIT_COMMITTER_NAME
export GIT_COMMITTER_EMAIL


cd $WORKSPACE/py-opt-cli
pip install -r requirements.txt
pip install -e .
env

cd $WORKSPACE/optimizely-experiments

# Retry 5 times before giving up on optimizely
for i in {1..5}
do
# Don't sleep the first time through the loop
[ $i -gt 1 ] && sleep 300

# Save the return-code of the pull command
py-opt-cli pull && s=0 && break || s=$?
done
# Fail the build with the return code of the pull command if it failed after 5 retries
(exit $s)

git add -A
git diff --cached --quiet || git commit -am "history commit job # ${BUILD_ID}"
git push origin HEAD:history
Loading