-
Improvement
-
Resolution: Unresolved
-
Critical
-
Jenkins version 2.3, all Plugins up to date. Debian 8 64 Bits x86.
-
Powered by SuggestiMate
I try to setup a pipeline project to build tags using a Jenkinsfile from SCM (Git). Therefore I want to be be able to set the tag I wish to build via the Git Parameter Plugin. If I setup the project like this and hit the "Build with Parameters" button the git parameter plugin tells me "!No Git repository configured in SCM configuration".
- params.PNG
- 15 kB
- pipeline.PNG
- 32 kB
- screenshot-3.png
- 72 kB
- screenshot-2.png
- 30 kB
- screenshot-1.png
- 40 kB
- Selection_104.png
- 50 kB
[JENKINS-34876] Git Parameters not working for Pipeline projects and Jenkinsfile from SCM
Me as well. You can't pass a parameter into the `Branch specifier` field of the pipeline SCM section, can you? I tried, unsuccessfully.
Not a duplicate. Rather missing Pipeline integration with this plugin.
I observed the same behavior, but I came up with a hacky workaround...
I wrote a shell script that will dump git tags into a sorted list that can be ingested as a property file when using the the Extended Choice Parameter plugin.
1) Run this script in the root of your git checkout dir:
git tag -l --sort=version:refname | sort -r | xargs echo -n | sed 's/ /,/g' | sed '1s/^/key=/' > /tmp/versions.properties
2) Install the Extended Choice Parameter plugin and add it to your job
https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin
3) Point the config to the property file you generated and set the key. See my attached example:
ganthore With your script, does this assume that the Git repo has already been checked out? I'm just wondering how to run the script before the Pipeline starts. It seems you need to run the script before the pipeline actually starts so that you can populate some variable with your desired tag. The question would be, where would the one line BASH command be executed?
Hi Guys,
I working on resolving this issue. I have prototype solution.
Which supports Pipline job.
I hope to resolved this in release 0.7.0 Releases schedule
Regards
Hey Scott,
Yes that is correct. I'd have the git repo poll and then ensure that the script is executed after each poll. I know it's not ideal, but it works for now until klimas7 gets things patched up.
Can you be a bit more detailed about your job setup? I get that the BASH command you have above will grab the list of tags, and that it will put that in a file, and that the Extended Choice parameter will read that file at build time. What I don't get is when that BASH command is executed? In Jenkins pipeline, there's no option to run a BASH script before the Extended Choice plugin grabs the list of tags.
Hey Scott,
I guess we could just run a script like this as an alternative on the Jenkins master so that the main workspace has access to the properties file:
git ls-remote -t https://github.com/jenkinsci/github-plugin | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1 | sort -b -t . -k 1,1nr -k 2,2nr -k 3,3r -k 4,4r -k 5,5r | uniq | xargs echo -n | sed 's/ /,/g' | sed '1s/^/key=/' > /tmp/versions.properties
That way we don't have to force Jenkins to double checkout the git repo per my older example.
There are a number of ways you could do this. The end goal is to make sure that the script runs on a regular basis or immediately after the jenkins workspace has polled the git repo.
For instance, you could have the script execute on the jenkins master directly through something as simple as a cron job.
Or, you could also try running it with a post-merge git hook in the workspace, that way it runs each time after a "git pull" occurs. Here is a basic example that you could modify for your needs:
https://gist.github.com/sindresorhus/7996717
If you're familiar with incron (http://inotify.aiken.cz/?section=incron&page=why&lang=en), you could have that daemon execute the script each time it notices a file change in the git checkout folder on the workspace.
... or just wait for this bug to get patched.
Hope this helps...
ganthore We currently "solve" the problem by doing essentially what you suggested at build time using a pipeline stage:
parallel ( getRepo1Tags: { sh("git ls-remote --quiet --tags --heads ${repo1GitUrl} | awk '{print \$2}' | grep -vi '{}' | cut -d/ -f1,2 --complement > ${repo1TmpTags}") }, getRepo2Tags: { sh("git ls-remote --quiet --tags --heads ${repo2GitUrl} | awk '{print \$2}' | grep -vi '{}' | cut -d/ -f1,2 --complement > ${repo2TmpTags}") } )
After that we use the "input" command in pipeline to pause the build and wait for user input.
def listofRepo1TagsBranches = readFile(repo1TmpTags).trim() def repo1TagBranch = input([message: 'Select a Git branch / tag', parameters: [[$class: 'ChoiceParameterDefinition', choices: listofRepo1TagsBranches, description: '', name: 'Repo 1 branch / tag to build']]]) def listofRepo2TagsBranches = readFile(repo2TmpTags).trim() def repo2TagBranch = input([message: 'Select a Git branch / tag', parameters: [[$class: 'ChoiceParameterDefinition', choices: listofRepo2TagsBranches, description: '', name: 'Repo 2 branch / tag to build']]])
This works if you're not using automated deployments. However, for our staging environments, we rely on a webhook to be called so that code is automatically pushed to staging. I'm not sure how you would parameterize this without this plugin getting updated for pipeline support. Anyway, I'll figure out another solution in the meantime.
Code changed in jenkins
User: Boguslaw Klimas
Path:
pom.xml
src/findbugs/excludesFilter.xml
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/AbstractJobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/AbstractProjectJobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/JobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/JobWrapperFactory.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/UnsupportedJobType.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/WorkflowJobWrapper.java
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages.properties
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages_pl.properties
src/test/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinitionTest.java
http://jenkins-ci.org/commit/git-parameter-plugin/3885d16c08943acd696a1c618d78687c4d63a0cb
Log:
JENKINS-34876 Git Parameters not working for Pipeline projects and Jenkinsfile from SCM
Hi
I was created branch feature/JENKINS-34876 where I added support to pipeline job.
I was left to implement one method - perhaps is not necessary I must check it. If you want, you can build plugin from source and check it
I plan to release plugin about 10 sep
Regards
Boguslaw
Code changed in jenkins
User: Boguslaw Klimas
Path:
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/AbstractProjectJobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/JobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/WorkflowJobWrapper.java
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages.properties
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages_pl.properties
http://jenkins-ci.org/commit/git-parameter-plugin/5fc8a95ef5d23d704ca4e60ff668671be924ee20
Log:
JENKINS-34876 Git Parameters not working for Pipeline projects and Jenkinsfile from SCM
Code changed in jenkins
User: klimas7
Path:
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java
http://jenkins-ci.org/commit/git-parameter-plugin/b9c7ef390108df624f14c88a45b0be5156ebfe86
Log:
JENKINS-34876 Git Parameters not working for Pipeline projects and Jenkinsfile from SCM
Code changed in jenkins
User: Boguslaw Klimas
Path:
pom.xml
src/findbugs/excludesFilter.xml
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/AbstractJobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/AbstractProjectJobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/JobWrapper.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/JobWrapperFactory.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/UnsupportedJobType.java
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/WorkflowJobWrapper.java
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages.properties
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/jobs/Messages_pl.properties
src/test/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinitionTest.java
http://jenkins-ci.org/commit/git-parameter-plugin/9b1243d06a5af91494417c8cd697d14af4669bf7
Log:
Merge pull request #36 from jenkinsci/feature/JENKINS-34876
Feature/jenkins 34876
Compare: https://github.com/jenkinsci/git-parameter-plugin/compare/f047198dda1e...9b1243d06a5a
Hi,
When can we expect the release of Git Parameter Plugin latest version i.e. 0.7.0
Hi,
I didn't have enough time in weekend, I'll do it today.
Sorry, for that
Regards
Boguslaw
I just tried 0.7.0 and I can choose git branches and tags in the drop down.
But I failed to use it as a variable in * Branch Specifier*, seems the variable is not parsed at all.
Hi, wyvernnot
I have configured a simple job:
Parameter:
Could you get me something more information? About your configuration.
Regards
Boguslaw
Hi, I am using Jenkins@2.7.4 with a pipeline project.
here is the params settings
here is the pipeline settings
Oh, I just tried String Parameters and it does not work neither.
So I guess the problem is not with Git Parameter plugin but SCM plugin.
Related issue is: https://issues.jenkins-ci.org/browse/JENKINS-34540
klimas7 Thank you for working on this ticket. I apologize for bringing it back up but I was wondering would it be possible to parametize git branches from the checkouts done in the Jenkinsfile pipeline? I was able to get this this to work in the Pipeline for the primary git source but my Jenkinsfile has additional git sources I also need to check out and would like to parametize those git source branches for selection.
it looks like is a problem in scripted pipeline. When i changed the script to declarative it worked
julian_linux, were you able to get it fixed. I'm experiencing a similar issue.
Hi! I am using Jenkins LTS 2.190.2 via Docker container and I'm experiencing this issue using a SCM declarative pipeline. I have an Extensible Choice param in the job that is letting me pick a branch, and then I am referring to the branch variable selection as
${webapp_branch}
in the pipeline settings for the Jenkinsfile in SCM (specifically GIT). Based on my reading of this issue, it seems as if folks think this is fixed? I am definitely able to repo consistently across a number of declarative pipeline jobs on my server. I have config extremely similar to wyvernnot's screenshots from 2016. klimas7 Any insight here?
Screenshots:
Error from build:
hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/heads/${webapp_branch}:refs/remotes/origin/${webapp_branch}" returned status code 128:
stdout:
stderr: fatal: Couldn't find remote ref refs/heads/${webapp_branch} at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2174)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1866)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:78)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:547)
at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:358)
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:113)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
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
Hi there. Got the same issue again. Git tag parameter been not delivered to git checkout action.
Jenkins:Jenkins 2.289.1
Parameter plugin:
Same here!