Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-56914

Git plugin does not seem to understand how to push all tags with '*'

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • git-plugin
    • None
    • Windows

      I have npm scripts which do all the magic required for incrementing package versions and generating the tag from that version. When it comes to getting the git plugin to push, however, if I configure the tag name to push as '*',

      git tag -l
      

      works the tag is recognised from the command line, and I see that command being issued by the git plugin, however, the tags are not pushed and the plugin errors:

      ERROR: Step ‘Git Publisher’ failed: Tag * does not exist and Create Tag is not specified, so failing.

      I would expect the git plugin to push any tags matched by the name parameter. Even better if I could just say "push all tags" – tagging doesn't have to be the responsibility of this plugin.
       

          [JENKINS-56914] Git plugin does not seem to understand how to push all tags with '*'

          Mark Waite added a comment -

          If you're using a Jenkins Pipeline job, you can perform the push directly from the build script using either a withCredentials step (for https) or the sshagent step (for ssh).

          The withCredentials step defines variables for the username and password which the statements inside the block can use to reference the username and password in the git command line. Refer to the credentials binding plugin documentation on jenkins.io

          A similar technique can be used with git repositories using the ssh protocol by using an sshagent step. Refer to the sshagent pipeline step documentation on jenkins.io

          Mark Waite added a comment - If you're using a Jenkins Pipeline job, you can perform the push directly from the build script using either a withCredentials step (for https) or the sshagent step (for ssh). The withCredentials step defines variables for the username and password which the statements inside the block can use to reference the username and password in the git command line. Refer to the credentials binding plugin documentation on jenkins.io A similar technique can be used with git repositories using the ssh protocol by using an sshagent step. Refer to the sshagent pipeline step documentation on jenkins.io

          Davyd McColl added a comment -

          I don't have control over credentials or the machine in question, so I don't think I can get ssh agent working – currently the job uses stored credentials to clone / fetch.

           

          The pipeline idea sounds like it might be the winner, but I'm not making sense of the documentation – it probably makes a lot of sense to someone who has worked with a pipeline before, but I've used Jenkins only as a "run commands to do things" CI server. How do I even get started? Is the a concrete example of injecting known git credentials for a windows batch / powershell job? Thanks for any assistance.

           

          -d
           

          Davyd McColl added a comment - I don't have control over credentials or the machine in question, so I don't think I can get ssh agent working – currently the job uses stored credentials to clone / fetch.   The pipeline idea sounds like it might be the winner, but I'm not making sense of the documentation – it probably makes a lot of sense to someone who has worked with a pipeline before, but I've used Jenkins only as a "run commands to do things" CI server. How do I even get started? Is the a concrete example of injecting known git credentials for a windows batch / powershell job? Thanks for any assistance.   -d  

          Mark Waite added a comment -

          The CloudBees Pipeline Fundamentals course is free as a self-paced course. It provides a lab environment as a virtual machine image and 8 hours of training to use the Blue Ocean user interface to define a declarative Pipeline.

          That course will teach you how to define a declarative Pipeline using Blue Ocean and place that Pipeline in your source code repository as a Jenkinsfile. Inside that Jenkinsfile you'll use batch or powershell to call the same npm script that you're using in your Freestyle job. The course will teach you about post steps. You can then add a withCredentials block inside the post step to push the tags when the job succeeds.

          Since the Freestyle job you're using is allowed to push tags to the repository with the GitPublisher, the Jenkins environment has the credentials. They are likely assigned to the git checkout step from the user interface.

          Mark Waite added a comment - The CloudBees Pipeline Fundamentals course is free as a self-paced course. It provides a lab environment as a virtual machine image and 8 hours of training to use the Blue Ocean user interface to define a declarative Pipeline. That course will teach you how to define a declarative Pipeline using Blue Ocean and place that Pipeline in your source code repository as a Jenkinsfile. Inside that Jenkinsfile you'll use batch or powershell to call the same npm script that you're using in your Freestyle job. The course will teach you about post steps. You can then add a withCredentials block inside the post step to push the tags when the job succeeds. Since the Freestyle job you're using is allowed to push tags to the repository with the GitPublisher, the Jenkins environment has the credentials. They are likely assigned to the git checkout step from the user interface.

          Davyd McColl added a comment -

          Thanks, I'll check that out. Seems like a lot of effort to just push all tags, but I guess I have to do what I have to do (:
           

          Davyd McColl added a comment - Thanks, I'll check that out. Seems like a lot of effort to just push all tags, but I guess I have to do what I have to do (:  

          Mark Waite added a comment -

          You will be delighted with what you discover through Blue Ocean and the Declarative Pipeline. It is worth a little effort to discover that part of Jenkins.

          In terms of actually achieving your specific objective of pushing all tags, I'm confident that Declarative Pipeline will get you there much faster than waiting for the git plugin to implement that capability. That would require someone to create a git plugin pull request with tests that implements what you want. After the pull request is created, it must be reviewed and tested. After review and testing, it must be released. Since there are over 200000 installations of the git plugin, I'm hesitant to add new features without very strong support from multiple users.

          Mark Waite added a comment - You will be delighted with what you discover through Blue Ocean and the Declarative Pipeline. It is worth a little effort to discover that part of Jenkins. In terms of actually achieving your specific objective of pushing all tags, I'm confident that Declarative Pipeline will get you there much faster than waiting for the git plugin to implement that capability. That would require someone to create a git plugin pull request with tests that implements what you want. After the pull request is created, it must be reviewed and tested. After review and testing, it must be released. Since there are over 200000 installations of the git plugin, I'm hesitant to add new features without very strong support from multiple users.

            Unassigned Unassigned
            davydm Davyd McColl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: