Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Bitbucket repository slug #809

Open
ardrabczyk opened this issue Feb 13, 2024 · 2 comments
Open

Expose Bitbucket repository slug #809

ardrabczyk opened this issue Feb 13, 2024 · 2 comments

Comments

@ardrabczyk
Copy link

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

@ardrabczyk
Copy link
Author

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.

@ardrabczyk
Copy link
Author

ardrabczyk commented Feb 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant