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

can't get the plugin working with pipeline #205

Open
tonytvo opened this issue Jul 13, 2019 · 12 comments
Open

can't get the plugin working with pipeline #205

tonytvo opened this issue Jul 13, 2019 · 12 comments

Comments

@tonytvo
Copy link

tonytvo commented Jul 13, 2019

Hi,

for some reason, I couldn't get the pipeline working with bitbucketpr, here's my pipeline

pipeline {
    agent any 

    triggers {
        bitbucketpr(projectPath:'',
            bitbucketServer:'https://git.xxx.com',
            cron:'* * * * *',
            credentialsId:'xxxx',
            username:'',
            password:'',
            repositoryOwner:'xxxOwner',
            repositoryName:'xxxRepository',
            branchesFilter:'s:r:^finr',
            branchesFilterBySCMIncludes:false,
            ciKey:'jenkins',
            ciName:'Jenkins',
            ciSkipPhrases:'',
            checkDestinationCommit:false,
            approveIfSuccess:true,
            cancelOutdatedJobs:true,
            commentTrigger:'test this please')
    }

    stages {
        stage('Build') { 
            steps {
                echo "build"
            }
        }
        stage('Test') { 
            steps {
                echo "Test" 
            }
        }
    }
}

Although it seems to work for me when I did it through freestyle jobs, is there any recommendation?

Also, how can I debug this on my jenkins?
one way I could see is to checkout this project, build it and upload the hci manually to my jenkins and test it out, is there any gotchas I need to watch out for?

@CodeMonk
Copy link
Collaborator

I've never tried pipeline like that. I have always configured the trigger via the GUI:

Untitled

@ejrgilbert
Copy link

ejrgilbert commented Aug 2, 2019

@CodeMonk What version of the plugin are you using? I'm on 1.4.30 and am unable to get it to work with a SCM'ed pipeline. I have the trigger configured through the GUI and use the Git portion of the Source Code Management config to set up the Git repository to pull from.

However, the sourceBranch and targetBranch variables are not defined.

Possibly related to #130 ?

@ejrgilbert
Copy link

After looking a bit more, it seems the injectedEnvVars.txt isn't getting generated in any of the builds. And the console output for the Jenkins jobs don't have the line [EnvInject] - Loading node environment variables. This would make sense for why the environment variables aren't getting defined.

So it seems that the BitbucketAdditionalParameterEnvironmentContributor isn't getting triggered for some reason for pipeline builds? Hopefully this helps a bit.

@ejrgilbert
Copy link

Finally figured this out! I had to add the trigger via the Jenkins UI, then configure the job to checkout the pipeline from SCM via the UI, then add a checkout stage inside the pipeline to specify what to checkout which looks like this. Note, the types of quotation marks you use is important:

checkout([
    $class: 'GitSCM',
    branches: [[name: "*/${env.sourceBranch}"]],
    doGenerateSubmoduleConfigurations: false,
    extensions: [
        [
            $class: 'PreBuildMerge'],
            options: [mergeRemote: 'origin', mergeTarget: "${env.targetBranch}"]
    ],
    submoduleCfg: [],
    userRemoteConfigs: [[
        credentialsId: 'place-cred-id-here',
        refspec: '+refs/pull-requests/*: refs/remotes/origin/pr/*',
        url: "ssh://git@bitbucket-url-here:7999/${env.destinationRepositoryOwner}/${env.destinationRepositoryName}.git"
    ]]
])

The refspec pulls in the pr branches. This is important if your PRs are across forks!

@CodeMonk
Copy link
Collaborator

CodeMonk commented Aug 28, 2019 via email

@CodeMonk
Copy link
Collaborator

Hey, @tonytvo , I think the reason it's been broken is because of a merge squash.

Check out #211

Are you able to build and test a plugin? I'm going to hand test it when I have some time at work, but, it would be really helpful if you could test too.

It may turn the above back into checkout scm

@JasonDictos
Copy link

This seems related to an issue I posted today: #215

Any other way to get this to work then the above mentioned work around?

@CodeMonk
Copy link
Collaborator

That merge squash was fixed several weeks ago.

Are you still having issues?

@RayOei
Copy link

RayOei commented Feb 27, 2020

I seem to have the same issue.
Plugin version 1.5.0
As you can see this is triggered by the PR. But the subsequent SCM definition for the "Pipeline script from SCM" doesn't recognize the environment variable.
The build.xml in the Jenkins job directory does contain the 'sourceBranch' variable as far as I can make out.

Any idea?

<a href="https://bitbucket.org/xxxxx/xxxx/pull-request/43">#43 xx</a> hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune origin +refs/heads/${sourceBranch}:refs/remotes/origin/${sourceBranch}" returned status code 128: stdout: stderr: fatal: Couldn't find remote ref refs/heads/${sourceBranch} fatal: The remote end hung up unexpectedly at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2429) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2043) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:80) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:568) at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:352) at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197) at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:115) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:69) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:299) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Finished: FAILURE

@aetos382
Copy link

I have the same problem.
Plugin version 1.5.0

How should I set up the followings?

  • Jenkins pipeline job configuration GUI
  • trigger definition in Jenkinsfile
  • checkout step in Jenkinsfile

@CodeMonk
Copy link
Collaborator

  1. I use the gui and pipeline build
  2. The trigger definition is identical to the documentation: builder configured with creds, and repo name and account set correctly. Then, I use a jenkinsfile from the SCM.
  3. Finally, the checkout step I use in my Jenkinsfile is: checkout scm

There used to be issues with checkout scm, but, those were fixed in 1.5.0

@CodeMonk
Copy link
Collaborator

Keep in mind, you CANNOT click the rebuild button on a PR build. The branch information will not be present. You have to either push a new commit, rebase a new commit, or comment on the PR with the trigger phrase

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

No branches or pull requests

6 participants