Discussion:
How to git push from a Jenkinsfile?
Idan Adar
2017-03-24 11:37:56 UTC
Permalink
How do you get "git push" to work in a Jenkinsfile? I am not sure what am I
missing.

The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
The Jenkins file also does a merge of a PR in one of its stages:

withCredentials([usernamePassword(credentialsId: '****', usernameVariable:
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}

But I can't get "git push" to work in another stage:

git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git remote set-url origin git@****.git
git push origin master

I tried wrapping the above in withCredential and also . with agent, but
nothing works...

Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a32566df-2725-4c9d-a973-171ccc376ad8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 11:44:58 UTC
Permalink
Note: this is done in a declarative pipeline.

jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/82ba7859-bdde-4a55-a6b1-40e92b057be4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 11:50:45 UTC
Permalink
Examples:

git push '****:****@https://github.****.git/ <https://github.ibm.com/security-services/certificate-management-utils.git/>'


But it says: fatal: I don't handle protocol '****:****@https'

Then also tried:

git remote set-url origin https://****:****@github.****.git <https://****:****@github.ibm.com:security-services/certificate-management-utils.git>
git push origin master


But it fails with:
fatal: unable to access 'https://****:****@github.****.com:****.git/
<https://****:****@github.ibm.com:security-services/certificate-management-utils.git/>':
Could not resolve host: ****:****@github.****.com; Name or service not known

With sshagent:

git remote set-url origin ***@github.****.com:****.git
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Post by Idan Adar
Note: this is done in a declarative pipeline.
jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****', usernameVariable
: 'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)])
{
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Waite
2017-03-24 12:05:19 UTC
Permalink
PR452 is a pending pull request for the git plugin which adds GitPublisher
support to pipeline.

If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi
,
you could provide feedback on that pull request to tell if it works for you
or not.

Mark Waite
Post by Idan Adar
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Note: this is done in a declarative pipeline.
jglick, thoughts?
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtEfzjJtC5YkRiU%3D7BVwyrA7WhKH4QMErAtVpNUifjMqKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 12:11:33 UTC
Permalink
I can try.
What are the instructions after updating the plugin?
Post by Mark Waite
PR452 is a pending pull request for the git plugin which adds GitPublisher
support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
Post by Idan Adar
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Post by Idan Adar
Note: this is done in a declarative pipeline.
jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what
am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent,
but nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Waite
2017-03-24 12:16:20 UTC
Permalink
I suspect that the "Pipeline Syntax" link will display a new step "Git
Publisher" which can then be used to generate the Jenkinsfile syntax for
the Git Publisher.

If you're using declarative, then I suspect that it's user interface will
also show a Git Publisher step.

Mark Waite
Post by Idan Adar
I can try.
What are the instructions after updating the plugin?
PR452 is a pending pull request for the git plugin which adds GitPublisher
support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Note: this is done in a declarative pipeline.
jglick, thoughts?
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtFoMjyM5m7yN0hjjdod2My8ZQFQCG9RDXcpBX%2BdG8PVxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 12:29:56 UTC
Permalink
So, a scenario: assuming I have checked out the master branch, ran some
unit tests and if all is okay I published to npm...
I now up the version number in package.json and I want this change pushed
back to master... using this plugin and the following generated snippet:

gitPublisher branchesToPush: [[branchName: 'master']], credentialsId:
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: '****'

The master branch should be updated the changed file?
Post by Mark Waite
I suspect that the "Pipeline Syntax" link will display a new step "Git
Publisher" which can then be used to generate the Jenkinsfile syntax for
the Git Publisher.
If you're using declarative, then I suspect that it's user interface will
also show a Git Publisher step.
Mark Waite
Post by Idan Adar
I can try.
What are the instructions after updating the plugin?
Post by Mark Waite
PR452 is a pending pull request for the git plugin which adds
GitPublisher support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
Post by Idan Adar
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Post by Idan Adar
Note: this is done in a declarative pipeline.
jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure
what am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent,
but nothing works...
Tips?
--
You received this message because you are subscribed to the Google
Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send
Post by Idan Adar
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5bb2dfdb-ce0b-4c45-9714-63997c74dd91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 12:31:56 UTC
Permalink
More context:

sh "npm --no-git-tag-version version minor"

// commit the updated version number back to GHE
sh "git commit -am 'Bumped version number [ci skip]'"
gitPublisher branchesToPush: [[branchName: 'master']], credentialsId:
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: 'https://***'
Post by Idan Adar
So, a scenario: assuming I have checked out the master branch, ran some
unit tests and if all is okay I published to npm...
I now up the version number in package.json and I want this change pushed
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: '****'
The master branch should be updated the changed file?
Post by Mark Waite
I suspect that the "Pipeline Syntax" link will display a new step "Git
Publisher" which can then be used to generate the Jenkinsfile syntax for
the Git Publisher.
If you're using declarative, then I suspect that it's user interface will
also show a Git Publisher step.
Mark Waite
Post by Idan Adar
I can try.
What are the instructions after updating the plugin?
Post by Mark Waite
PR452 is a pending pull request for the git plugin which adds
GitPublisher support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
Post by Idan Adar
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Post by Idan Adar
Note: this is done in a declarative pipeline.
jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure
what am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent,
but nothing works...
Tips?
--
You received this message because you are subscribed to the Google
Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send
Post by Idan Adar
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f94f0eab-895d-4b54-bf95-7c2270b2234f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Waite
2017-03-24 12:34:19 UTC
Permalink
That seems reasonable. I haven't evaluated that pull request, so I don't
know the steps for sure, that's just my assumption.

Mark Waite
Post by Idan Adar
sh "npm --no-git-tag-version version minor"
// commit the updated version number back to GHE
sh "git commit -am 'Bumped version number [ci skip]'"
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: 'https://***'
So, a scenario: assuming I have checked out the master branch, ran some
unit tests and if all is okay I published to npm...
I now up the version number in package.json and I want this change pushed
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: '****'
The master branch should be updated the changed file?
I suspect that the "Pipeline Syntax" link will display a new step "Git
Publisher" which can then be used to generate the Jenkinsfile syntax for
the Git Publisher.
If you're using declarative, then I suspect that it's user interface will
also show a Git Publisher step.
Mark Waite
I can try.
What are the instructions after updating the plugin?
PR452 is a pending pull request for the git plugin which adds GitPublisher
support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Note: this is done in a declarative pipeline.
jglick, thoughts?
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/f94f0eab-895d-4b54-bf95-7c2270b2234f%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/f94f0eab-895d-4b54-bf95-7c2270b2234f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGDScJWkH9n08XW-58JGf%3D45DdCrx1O%2B3Zu8zoYj7zNRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 12:41:10 UTC
Permalink
Unfortunately it fails with ERROR: No branch repo to push to defined
Post by Mark Waite
That seems reasonable. I haven't evaluated that pull request, so I don't
know the steps for sure, that's just my assumption.
Mark Waite
Post by Idan Adar
sh "npm --no-git-tag-version version minor"
// commit the updated version number back to GHE
sh "git commit -am 'Bumped version number [ci skip]'"
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: 'https://***'
Post by Idan Adar
So, a scenario: assuming I have checked out the master branch, ran some
unit tests and if all is okay I published to npm...
I now up the version number in package.json and I want this change
pushed back to master... using this plugin and the following generated
'caf2691d-42c7-4d10-acf0-cf5fcc2575a4', url: '****'
The master branch should be updated the changed file?
Post by Mark Waite
I suspect that the "Pipeline Syntax" link will display a new step "Git
Publisher" which can then be used to generate the Jenkinsfile syntax for
the Git Publisher.
If you're using declarative, then I suspect that it's user interface
will also show a Git Publisher step.
Mark Waite
Post by Idan Adar
I can try.
What are the instructions after updating the plugin?
Post by Mark Waite
PR452 is a pending pull request for the git plugin which adds
GitPublisher support to pipeline.
If you're willing to download and test
https://ci.jenkins.io/job/Plugins/job/git-plugin/view/change-requests/job/PR-452/lastSuccessfulBuild/artifact/target/git.hpi ,
you could provide feedback on that pull request to tell if it works for you
or not.
Mark Waite
Post by Idan Adar
git push origin master
+ git push origin master
Host key verification failed.
fatal: Could not read from remote repository.
Post by Idan Adar
Note: this is done in a declarative pipeline.
jglick, thoughts?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure
what am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent,
but nothing works...
Tips?
--
You received this message because you are subscribed to the Google
Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it,
Post by Idan Adar
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/16980860-a0fc-42d0-b091-eb5f607001fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/193a2714-f9f3-48c5-8eb8-06df36c4febc%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/f94f0eab-895d-4b54-bf95-7c2270b2234f%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/f94f0eab-895d-4b54-bf95-7c2270b2234f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/acb8f0e1-e048-44a3-8150-aab1949134db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Joshua Noble
2017-03-24 13:18:27 UTC
Permalink
Generally when you do a basic checkout, the Jenkins workspace is in a
detached HEAD state. You want to check out to a local branch likely using "
localBranch". I have to ask though - if Jenkins does a merge of the PR -
why would you need to push?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is configured
in the Jenkins UI for the job).
'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a26230a4-0d7f-4562-8012-d10c35973739%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 13:31:59 UTC
Permalink
Thanks for the question Joshua.
Here's the full Jenkinsfile: http://pastebin.com/nG4iTZhQ

What happens is this:
1. Developers make a pull request to the master branch from their feature
branch.
2. The pull_request webhook tells Jenkins to start working based on the
stages in the Jenkinsfile. This includes: checkout, unit test, sonar
analysis and merge to master.
3. The effect of the merge is basically a push webhook, which means that
Jenkins is now going to run the same Jenkinsfile, but on the master branch
instead of the Pull Request. So, this time: checkout, unit tests and
publish to npm.

In the case where it is running from the master branch, I also bump the
version number in package.json and want to push this change back to the
master branch.
Developers will then update their feature branch with the updated
package.json number...

The part that is not working is the git push.
You have mentioned "localbranch". I haven't heard of this or know how to do
this. Can you elaborate?
Post by Joshua Noble
Generally when you do a basic checkout, the Jenkins workspace is in a
detached HEAD state. You want to check out to a local branch likely using "
localBranch". I have to ask though - if Jenkins does a merge of the PR -
why would you need to push?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what am
I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****', usernameVariable
: 'ACCESS_TOKEN_USERNAME', passwordVariable: 'ACCESS_TOKEN_PASSWORD',)])
{
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cc07dca8-2b77-43a6-a9f0-a94217e29c8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-24 14:37:58 UTC
Permalink
Joshua, perhaps you mean something like this?
The git commands likely miss something...

stage ("Publish to npm") {
steps {
script {
STAGE_NAME = "Publish to npm"
}

// Prepare the workspace
deleteDir()
sh '''
git checkout -b master
npm --no-git-tag-version version minor
git commit -am 'Bumped version number [ci skip]'
git push origin master
'''
}
}
}
Post by Idan Adar
Thanks for the question Joshua.
Here's the full Jenkinsfile: http://pastebin.com/nG4iTZhQ
1. Developers make a pull request to the master branch from their feature
branch.
2. The pull_request webhook tells Jenkins to start working based on the
stages in the Jenkinsfile. This includes: checkout, unit test, sonar
analysis and merge to master.
3. The effect of the merge is basically a push webhook, which means that
Jenkins is now going to run the same Jenkinsfile, but on the master branch
instead of the Pull Request. So, this time: checkout, unit tests and
publish to npm.
In the case where it is running from the master branch, I also bump the
version number in package.json and want to push this change back to the
master branch.
Developers will then update their feature branch with the updated
package.json number...
The part that is not working is the git push.
You have mentioned "localbranch". I haven't heard of this or know how to
do this. Can you elaborate?
Post by Joshua Noble
Generally when you do a basic checkout, the Jenkins workspace is in a
detached HEAD state. You want to check out to a local branch likely using "
localBranch". I have to ask though - if Jenkins does a merge of the PR -
why would you need to push?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what
am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent, but
nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8dc9d4fe-b60e-4576-b855-b703e9283cb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kevin Burnett
2017-03-25 04:08:55 UTC
Permalink
you may want to omit the -b in "git checkout -b master" if the master
branch already exists (seems likely).

we use this to make maven release work on any branch (maven release has a
similar issue where it cannot work with detached head):

sh 'git checkout ' + env.BRANCH_NAME
Post by Idan Adar
Joshua, perhaps you mean something like this?
The git commands likely miss something...
stage ("Publish to npm") {
steps {
script {
STAGE_NAME = "Publish to npm"
}
// Prepare the workspace
deleteDir()
sh '''
git checkout -b master
npm --no-git-tag-version version minor
git commit -am 'Bumped version number [ci skip]'
git push origin master
'''
}
}
}
Post by Idan Adar
Thanks for the question Joshua.
Here's the full Jenkinsfile: http://pastebin.com/nG4iTZhQ
1. Developers make a pull request to the master branch from their feature
branch.
2. The pull_request webhook tells Jenkins to start working based on the
stages in the Jenkinsfile. This includes: checkout, unit test, sonar
analysis and merge to master.
3. The effect of the merge is basically a push webhook, which means that
Jenkins is now going to run the same Jenkinsfile, but on the master branch
instead of the Pull Request. So, this time: checkout, unit tests and
publish to npm.
In the case where it is running from the master branch, I also bump the
version number in package.json and want to push this change back to the
master branch.
Developers will then update their feature branch with the updated
package.json number...
The part that is not working is the git push.
You have mentioned "localbranch". I haven't heard of this or know how to
do this. Can you elaborate?
Post by Joshua Noble
Generally when you do a basic checkout, the Jenkins workspace is in a
detached HEAD state. You want to check out to a local branch likely using "
localBranch". I have to ask though - if Jenkins does a merge of the PR
- why would you need to push?
Post by Idan Adar
How do you get "git push" to work in a Jenkinsfile? I am not sure what
am I missing.
The Jenkinsfile checkouts a repo using an access token (this is
configured in the Jenkins UI for the job).
withCredentials([usernamePassword(credentialsId: '****',
'ACCESS_TOKEN_PASSWORD',)]) {
sh "curl -X PUT -d '{\"commit_title\": \"Merge pull request\"}'
https://***/pulls/$CHANGE_ID/merge?access_token=$ACCESS_TOKEN_PASSWORD"
}
git config --global user.name '****'
git config --global user.email ****
git commit -am 'Bumped version number'
git push origin master
I tried wrapping the above in withCredential and also . with agent,
but nothing works...
Tips?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b96ad9e4-a965-4455-9ef0-f3d27cf9c06a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Idan Adar
2017-03-25 06:26:20 UTC
Permalink
Okay, solved at last.

In addition to the below stage, for your reference, I had to also add the
id_rsa and id_rsa.pub files to ~/.ssh. Then I had to do a git push manually
from the command line which then instructed me to trust the ssh key.
Following this, the script from the stage then worked.

The problem I am facing now is that it seems the "ci skip" plug-in is not
working. Despite the presence of "[ci skip]" in the commit message, the job
is being triggered in a loop (because the job makes a push to the master
branch, meaning a push webhook again triggers it...

stage ("Publish to npm") {
steps {
script {
STAGE_NAME = "Publish to npm"

if (BRANCH_NAME == "master") {
// Publish to npm and bump the version number for the
next release
sh "npm publish"
deleteDir()
sshagent (credentials: [
'e276113e-0ec9-4eaa-88f9-a7db5c9635b6']) {
sh '''
git clone git@****.git
cd ****
npm --no-git-tag-version version minor
git config --global user.name "****"
git config --global user.email ****
git commit -am 'Bumped version number [ci skip]'
git push origin master
'''
}

slackSend (
color: '#199515',
message: "$JOB_NAME: Build #$BUILD_NUMBER passed
successfully."
)
}
else {
echo "Not in 'master' branch. Don't attempt publishing."
}
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5e4cd359-b0c1-4507-ab45-0a6df1ac5b66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...