Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tkrzeminski/jenkins-groovy-scripts
https://github.com/tkrzeminski/jenkins-groovy-scripts
Last synced: about 14 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/tkrzeminski/jenkins-groovy-scripts
- Owner: tkrzeminski
- Created: 2016-09-09T11:17:34.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-17T07:06:35.000Z (6 months ago)
- Last Synced: 2024-08-02T13:16:00.950Z (3 months ago)
- Language: Groovy
- Size: 28.3 KB
- Stars: 98
- Watchers: 4
- Forks: 56
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jenkins-groovy-scripts #
## Credentials ##
### Decode hashed secret ###
```groovy
println(hudson.util.Secret.decrypt("ENCODED_VALUE"))
```### Encode value ###
```groovy
println(hudson.util.Secret.fromString("alamakota").getEncryptedValue())
``````bash
echo 'println(hudson.util.Secret.fromString("loremIpsum").getEncryptedValue())' | java -jar ./.cli/jenkins-cli.jar -s http://localhost:8080/ groovy =
```### Run script which shows all credentials: ###
```bash
java -jar /var/lib/jenkins/.cli/jenkins-cli.jar -s http://localhost:8080 groovy /opt/groovyScripts/show-all-credentials.groovy
```### Show selected credentials as xml ###
```bash
java -jar /var/lib/jenkins/.cli/jenkins-cli.jar -s http://localhost:8080 get-credentials-as-xml "SystemCredentialsProvider::SystemContextResolver::jenkins" "(global)" CREDENTIAL ID
```### Create credentials domain: ###
```bash
cat /opt/provision/domain.xml | java -jar /var/lib/jenkins/.cli/jenkins-cli.jar -s http://localhost:8080/ create-credentials-domain-by-xml "SystemCredentialsProvider::SystemContextResolver::jenkins"
```domain.xml content:
```xmlGithubCredentials
```
### Create credentials ###
```bash
cat /opt/provision/credentials.xml | java -jar /var/lib/jenkins/.cli/jenkins-cli.jar -s http://localhost:8080/ create-credentials-by-xml "SystemCredentialsProvider::SystemContextResolver::jenkins" GithubCredentials
```credentials.xml content:
```xmlGLOBAL
jenkins-github-read-write-user
Github user for RW operations
someGithubUsername
typicalSecretPassword```
## Configuring CSP (Content Security Policy) ##
- Quick reference guide: https://content-security-policy.com/
- CSP evaluator: https://csp-evaluator.withgoogle.com/
- Jenkins Wiki: https://wiki.jenkins-ci.org/display/JENKINS/Configuring+Content+Security+Policy### Set CSP ###
```groovy
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox allow-same-origin allow-scripts allow-top-navigation;script-src 'unsafe-inline' 'self';default-src 'self'; img-src self data: http: https:; style-src self unsafe-inline; child-src 'self'; frame-src 'self';")
```
### Show CSP value ###
```groovy
System.getProperty("hudson.model.DirectoryBrowserSupport.CSP")
```