Skip to content

Instantly share code, notes, and snippets.

@loopmode
Last active August 21, 2019 12:09
Show Gist options
  • Save loopmode/4515b4d9b2de88ada49d807e9b14d10e to your computer and use it in GitHub Desktop.
Save loopmode/4515b4d9b2de88ada49d807e9b14d10e to your computer and use it in GitHub Desktop.
printing Gitlab CI/CD variables as key/value pairs.
(function getGitlabSecrets() {
const secrets = [
...document.querySelectorAll('.ci-variable-row-body'),
].reduce((result, row) => {
const key = row.querySelector(
'[name="variables[variables_attributes][][key]"]',
).value;
const value = row.querySelector(
'[name="variables[variables_attributes][][secret_value]"]',
).value;
if (key) {
Object.assign(result, { [key]: value });
}
return result;
}, {});
return secrets;
})();
javascript:(function showGitlabSecrets() {
const secrets = [
...document.querySelectorAll('.ci-variable-row-body'),
].reduce((result, row) => {
const key = row.querySelector(
'[name="variables[variables_attributes][][key]"]',
).value;
const value = row.querySelector(
'[name="variables[variables_attributes][][secret_value]"]',
).value;
if (key) {
result.push(`${key}=${value.split('\n').join('\\\n')}`);
}
return result;
}, []);
const el = document.createElement('pre');
el.innerHTML = secrets.join('\n');
document.getElementById('content-body').prepend(el);
})();
javascript:(function showGitlabSecretsJSON() {
const secrets = [
...document.querySelectorAll('.ci-variable-row-body'),
].reduce((result, row) => {
const key = row.querySelector(
'[name="variables[variables_attributes][][key]"]',
).value;
const value = row.querySelector(
'[name="variables[variables_attributes][][secret_value]"]',
).value;
if (key) {
Object.assign(result, { [key]: value });
}
return result;
}, {});
const el = document.createElement('pre');
el.innerHTML = JSON.stringify(secrets, null, 2);
document.getElementById('content-body').prepend(el);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment