Adjust Rundeck API for adding jobs
Description
For now Rundeck role has project and jobs API that assumes user has know everything how Rundeck works. We could simplify our API to user that someone asks for project and jobs with only part of job that do what is needed. Creating workspace for job, and cleaning after it could be by default added to all requested jobs definition.
Proposal
Add template to role which at the begining have some commands which are neccesery for each job for example something like this:
#!/bin/bash
# --- Job Wrapper Begin --- #
set -o errexit
export RUNDECK_DATA="/home/rundeck/work"
export RUNDECK_JOB_SCOPE="${RD_JOB_PROJECT}/${RD_JOB_EXECID}"
export RUNDECK_JOB_WORKSPACE="${RUNDECK_DATA}/work/${RUNDECK_JOB_SCOPE}"
# --- Workspace Creation --- #
echo "Creating workspace ${RUNDECK_JOB_WORKSPACE}"
mkdir --parents ${RUNDECK_JOB_WORKSPACE}
cd ${RUNDECK_JOB_WORKSPACE}
# --- Workspace Cleanup --- #
function clean_workspace {
echo "Running cleanup - removing workspace ${RUNDECK_JOB_WORKSPACE}"
rm --recursive --force ${RUNDECK_JOB_WORKSPACE}
}
trap clean_workspace EXIT
# --- Job Wrapper End --- #
And here job definition defined by user
Things that are worth to mention for user.
- Every password type things should be defined as job option/project credentials and used in script as
"@option.{{ option_name }}@"
thinks like tokens, passwords, webhooks etc.
Needed API changes:
- Changes in API will limit to
rundeck_projects
variable definition- remove
template
option fromjob
definition and addscript
option instead which could look like this:rundeck_projects: name: "project_name" jobs: - name: "job name" description: "job description" options: some options script: workspace: yes content: "script content" # for example from some file or template lookup
yes
- remove
Edited by Krzysztof Szymański