jenkinsci/bitbucket-branch-source-plugin

Expose Bitbucket repository slug

Opened this issue · 2 comments

What feature do you want to see added?

I'm switching away from Bamboo and I'm looking for an equivalent of bamboo_planRepository_1_name. It would be easier to have a ready to use variable than to parse GIT_URL manually.

Upstream changes

No response

Are you interested in contributing this feature?

No response

I can do as they do here https://github.com/rtyler/jdp/blob/main/data/valid/generated-parallel-wrapped-by-declarative/Jenkinsfile:

	script {
	    def jobs = Jenkins.instance.getAllItems()
	    jobs.each { j ->
		def scmsrc = []
		if (j instanceof org.jenkinsci.plugins.workflow.job.WorkflowJob) {
		    scmsrc = j.getSCMs()
		} else {
		    try {
			scmsrc = j.SCMSources
		    } catch (Exception eSCMsrc) {
			echo "No supported SCM source variable found: " + eSCMsrc;
		    }
		}
		if (scmsrc.size() >0)
		    for (scm in scmsrc) {
		    String url = ""
		    if (scm instanceof com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) {
			echo "BitbucketSCM...";
			echo scm.getRepoOwner()
			echo scm.getRepository()
		    }
		}

	    }
	}

but it requires approving a lot of scripts and is hard to use.

It could be simplified, complete Jenkinsfile could look like this:

def determineRepoSlug() {
    def a = Jenkins.instance.getItem("${env.JOB_NAME}".tokenize("/")[0])
    return a.SCMSources[0].getRepoOwner() + "/" + a.SCMSources[0].getRepository()
}

pipeline {
    agent {
	docker {
	    image 'ubuntu'
	    label 'ard'
	}
    }

    environment {
        BITBUCKET_REPO_SLUG="${determineRepoSlug()}"
    }

    stages {
        stage('build') {
            steps {
		sh "env"
	    }
	}
    }
}

Nonetheless a variable exposed by the plugin would be useful.