Global variables for Jenkins pipelines
1 day ago
Ever found yourself needing to be able to use the same variable over and over for many pipelines? Here’s how:
- Make a
vars/globals.groovy
file in your shared library - Put this in it:
#!/usr/bin/env groovy
import groovy.transform.Field
@Field final String GITHUB_URL = 'https://github.com/'
@Field final String GITHUB_SLUG = 'k-caps'
3. Access the constant from your Jenkinsfiles:
repoUrl = globals.GITHUB_URL + globals.GITHUB_SLUG
You can access it from other files under vars the exact same way, too.