Skip to content

Commit

Permalink
Implement test for checking osrfbuild credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
  • Loading branch information
j-rivero committed Nov 15, 2024
1 parent 4d7585a commit 07a29cb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jenkins-scripts/dsl/_configs_/GitHubCredentials.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class GitHubCredentials
job.with
{
wrappers {
// credential name needs to be in sync with provision code at infra/osrf-chef repo
// Credential name needs to be in sync with provision code at infra/osrf-chef repo
credentialsBinding {
string('GITHUB_TOKEN', 'osrfbuild-token')
usernamePassword('OSRFBUILD_USER', 'OSRFBUILD_TOKEN', 'github-osrfbuild-credentials')
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions jenkins-scripts/dsl/test.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,63 @@ outdated_job_runner.with
systemGroovyCommand(readFileFromWorkspace('scripts/jenkins-scripts/tools/outdated-job-runner.groovy'))
}
}

// --------------------------------------------------------------------
def test_credentials_token_job = job("_test_job_osrfbuild-credentials-token_from_dsl")
OSRFBase.create(test_credentials_token_job)
GitHubCredentials.createOsrfbuildToken(test_credentials_token_job)
test_credentials_token_job.with
{
label "docker"

steps {
shell("""\
#!/bin/bash -xe

echo "Testing the login into the Jenkins server:"
curl --silent --fail --write '\\nReturn code: %{http_code}\\n' --user "\${OSRFBUILD_USER}:\${OSRFBUILD_TOKEN}" \${JENKINS_URL} --output /dev/null
""".stripIndent())

shell("""\
#!/bin/bash -xe

# Check push+commit permissions for osrfbuild by uploading/deleting a
# branch. Note that call to the API for permissions require of admin
# perms that osrfbuild user does not have. Personal tokens don't
# support ssh but https only.

rm -fr homebrew-simulation
git clone https://github.com/\${OSRFBUILD_USER}/homebrew-simulation.git
cd homebrew-simulation
git config user.name \${OSRFBUILD_USER} --replace-all
git config user.email "\${OSRFBUILD_USER}@openrobotics.org" --replace-all
git config url."https://\${OSRFBUILD_USER}:\${OSRFBUILD_TOKEN}@github.com/\${OSRFBUILD_USER}/homebrew-simulation.git".InsteadOf https://github.com/\${OSRFBUILD_USER}/homebrew-simulation.git
git checkout -b _test_job_osrfbuild_
git commit --allow-empty -m "testing commit"
# protect token from errors
git push -u origin _test_job_osrfbuild_ > push_log
git push origin --delete _test_job_osrfbuild_ >> push_log
""".stripIndent())
}

publishers
{
postBuildScripts {
steps {
shell("""\
#!/bin/bash -xe

# remove token after the build ends unconditionally
rm -fr \${WORKSPACE}/homebrew-simulation/.git/config
""".stripIndent())
}

onlyIfBuildSucceeds(false)
onlyIfBuildFails(false)
}
}

wrappers {
preBuildCleanup()
}
}

0 comments on commit 07a29cb

Please sign in to comment.