{"id":19866462,"url":"https://github.com/devopsmakers/jenkins-get-library-version","last_synced_at":"2026-05-13T04:42:32.084Z","repository":{"id":95879420,"uuid":"333203607","full_name":"devopsmakers/jenkins-get-library-version","owner":"devopsmakers","description":"A Jenkins shared library helper function to help load different versions based on job name","archived":false,"fork":false,"pushed_at":"2021-01-28T16:28:54.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-11T15:48:03.187Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devopsmakers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-26T20:08:32.000Z","updated_at":"2021-01-28T16:28:56.000Z","dependencies_parsed_at":"2023-03-14T19:45:46.408Z","dependency_job_id":null,"html_url":"https://github.com/devopsmakers/jenkins-get-library-version","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devopsmakers%2Fjenkins-get-library-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devopsmakers%2Fjenkins-get-library-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devopsmakers%2Fjenkins-get-library-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devopsmakers%2Fjenkins-get-library-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devopsmakers","download_url":"https://codeload.github.com/devopsmakers/jenkins-get-library-version/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241275551,"owners_count":19937368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T15:25:56.781Z","updated_at":"2026-05-13T04:42:32.057Z","avatar_url":"https://github.com/devopsmakers.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jenkins-get-library-version\nA Jenkins shared library helper function to help load different versions based on job name.\n\n## What is this?\nOn my travels through Jenkins, Groovy Shared Library, and Declarative Pipeline. I read the internet, and watched\nmany Jenkins World talks, often with conflicting opinions and ideas.\n\nOne of the talks had an interesting pattern with some plugin or something that ran some code before loading a projects\n`Jenkinsfile` to use a version of their shared library, latest or stable, depending on some environment variabe and a regex.\n\nI can't remember which talk it is, but I'll add a link here if I ever find it.\n\nThis is an attempt at creating a small library that could be used to do the same thing in a `Jenkinsfile` like this:\n```groovy\n#!groovy\ndef libraryVersion = getLibraryVersion()\nlibrary \"myRealLibrary@${libraryVersion}\"\n\npipeline {\n  agent any\n  stages {\n    stage('Library Dynamically Loaded!') {\n      steps {\n        echo \"Using library version: ${libraryVersion}\"\n      }\n    }\n  }\n}\n```\n\n## Why is this?\nTypically, pipeline library versioning goes one of 2 ways... People either pin to `main` and en(joy|dure) the\nexhilaration of innovation, or they pin to a branch, tag, sha of a library and make moving forwards difficult.\n\nI've decided that having different versions based on `JOB_NAME` is sensible. This way you could match jobs beginning\nwith `pipeline-test` and have them use some \"latest\" version (tag, branch, whatever...), and all other jobs could\nreference a slower moving \"stable\" version.\n\n## How is this?\nMost of the configuration is done with environment variables that should be set at the global configuration level:\n### Required:\n\n#### Plugins:\n- [HTTP Request](https://plugins.jenkins.io/http_request/)\n\n#### Environment Variables:\n- `LIBRARY_REPO` - The Github `org/repo` that your main shared library lives in. This is used to query the Github API\n  for the latest release `tag_name`.\n  \n- `LIBRARY_LATEST_JOB_MATCHER` - The pattern to match jobs for the \"latest\" library version.\n  Example: `^pipeline-test|^my-cool-jobs`.\n  \n### Optional:\n#### Environment Variables:\n- `LIBRARY_DEFAULT_STABLE_VERSION` - Override the default \"stable\" version. Default: `stable`.\n- `LIBRARY_DEFAULT_LATEST_VERSION` - Override the default \"latest\" version. Sometimes, you might just want to use\nthe `main` branch and not worry about creating Github releases. Defaults to Github \"Latest Release\" tag.\n  \n- `GITHUB_API_URL` - Override the Github API URL for GIthub Enterprise users. Default: `api.github.com`.\n- `GITHUB_CREDENTIALS_ID` - The ID of a credential within Jenkins that holds the username and personal access token to use\nwhen querying the Github API. Required if `LIBRARY_REPO` is private.\n  \n## Library Configuration\n1. Add this library to the Global Configuration and make sure that it is implicitly loaded. Meaning that it will be\n   available in any pipeline.\n   \n2. Add your main library without implicitly loading it. Your `Jenkinsfile` will be responsible for loading it explicitly.\nSadly, you can't load a library dynamically if it is already implicitly loaded. Jenkins will always use the first library\n   configuration that it finds. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevopsmakers%2Fjenkins-get-library-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevopsmakers%2Fjenkins-get-library-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevopsmakers%2Fjenkins-get-library-version/lists"}