Skip to content

Feature request: Allow version value to be set by an environmental variable  #23

@RoyWarps

Description

@RoyWarps

We have a peculiar use case, which we resolved by producing our own gem for now. But it could be useful in the official GVB.
In order to test our tool it is ran inside another repository. Typically GVB would then be use in such a way that it would retrieve the version from the gemspec. However as the tool is being tested it is not yet published and as such there is no .gemspec to retrieve a value from.
This causes a fallback to the version value of the local git repo which is not of the tool itself and thus results in a invalid version value.
We solved kinda quick and dirty by setting an environment variable GVB_NO_GEMSPEC_NO_GIT with a test version value.
If GVB finds the environment variable GVB_NO_GEMSPEC_NO_GIT with a value other than false its value is returned as the version.
If the environment variable GVB_NO_GEMSPEC_NO_GIT is not found or its value is false GVB will opperate normally.

	def self.version(use_local_dir=false, include_lite_tags=false)
		return ENV['GVB_NO_GEMSPEC_NO_GIT'] if ENV.key?('GVB_NO_GEMSPEC_NO_GIT') and !ENV['GVB_NO_GEMSPEC_NO_GIT'].eql?('false')
		if use_local_dir
			repo_version(true, include_lite_tags)
		else
			gem_version || repo_version(false, include_lite_tags)
		end
	end

The value false is necessary as Jenkins has the limitation that stages can only override environment variables not define additional ones. That unfortunately made the solution somewhat less pretty as it now has to perform multiple checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions