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

Pipeline step to run Git commands with credentials & tool

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • 4.8.0 - released username / password credential binding

      It would be nice to be able to use the GitPublisher inside a workflow as it is possible in other jobs.

      This requires the plugin to be upgrade to Jenkins core 1.580.1+, to implement the jenkins.tasks.SimpleBuildStep in GitPublisher

          [JENKINS-28335] Pipeline step to run Git commands with credentials & tool

          Adrien Lecharpentier created issue -
          Jesse Glick made changes -
          Labels New: workflow

          Jesse Glick added a comment -

          I already considered this possibility but do not consider it straightforward. GitPublisher relies on obtaining the single GitSCM configured for the project; there is no equivalent concept for Workflow.

          Anyway the extensive hardcoded logic in this publisher probably does not make sense in an otherwise flexible script. More useful would be an independent Step which lets you run arbitrary git commands, integrates with Credentials for authentication, and lets you pick a GitTool (certainly CLI, perhaps also JGit).

          Jesse Glick added a comment - I already considered this possibility but do not consider it straightforward. GitPublisher relies on obtaining the single GitSCM configured for the project; there is no equivalent concept for Workflow. Anyway the extensive hardcoded logic in this publisher probably does not make sense in an otherwise flexible script. More useful would be an independent Step which lets you run arbitrary git commands, integrates with Credentials for authentication, and lets you pick a GitTool (certainly CLI, perhaps also JGit).
          Jesse Glick made changes -
          Issue Type Original: Improvement [ 4 ] New: New Feature [ 2 ]
          Priority Original: Trivial [ 5 ] New: Major [ 3 ]
          Summary Original: Be able to use GitPublisher in a workflow description New: Be able to use GitPublisher in a workflow

          Code changed in jenkins
          User: Jesse Glick
          Path:
          COMPATIBILITY.md
          http://jenkins-ci.org/commit/workflow-plugin/26beaf00bff3fc235cb73d53c77bf64b632fdc75
          Log:
          JENKINS-28335 Noting.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/26beaf00bff3fc235cb73d53c77bf64b632fdc75 Log: JENKINS-28335 Noting.
          Jesse Glick made changes -
          Summary Original: Be able to use GitPublisher in a workflow New: Step to run Git commands w/ credentials & tool (was: GitPublisher support)
          Jesse Glick made changes -
          Assignee Original: Nicolas De Loof [ ndeloof ]
          Jesse Glick made changes -
          Link New: This issue depends on JENKINS-26055 [ JENKINS-26055 ]

          Sverre Moe added a comment - - edited

          Meanwhile it is possible to use Groovy Post-build within Pipeline (formerly Workflow).

          Using this script one could publish git tags:

          def build = manager.build
          def workspace = build.getWorkspace()
          def listener = manager.listener
          def environment = build.getEnvironment(listener)
          
          final def project = build.getProject()
          final def gitScm = project.getScm()
          final GitClient gitClient = gitScm.createClient(listener, environment, build, workspace);
          
          final def gitTagName = "TAG_NAME"
          final def comment = "COMMENT"
          final def remoteURI = new URIish("origin")
          
          gitClient.tag(gitTagName, comment)
          gitClient.push().tags(true).to(remoteURI).execute()
          

          Sverre Moe added a comment - - edited Meanwhile it is possible to use Groovy Post-build within Pipeline (formerly Workflow). Using this script one could publish git tags: def build = manager.build def workspace = build.getWorkspace() def listener = manager.listener def environment = build.getEnvironment(listener) final def project = build.getProject() final def gitScm = project.getScm() final GitClient gitClient = gitScm.createClient(listener, environment, build, workspace); final def gitTagName = "TAG_NAME" final def comment = "COMMENT" final def remoteURI = new URIish( "origin" ) gitClient.tag(gitTagName, comment) gitClient.push().tags( true ).to(remoteURI).execute()

          Alexander Siniouguine added a comment - - edited

          djviking How do you run postbuild from within jenkinsfile itself, the "manager" object is not available when it runs (the actual jenkinsfile is here: https://github.com/VirtoCommerce/vc-module-core/blob/eeee111fb33e12f93c9bf64988a193627dfb533a/Jenkinsfile)

          Ideally I'd like to commit the file changed during the build (version file).

          Alexander Siniouguine added a comment - - edited djviking How do you run postbuild from within jenkinsfile itself, the "manager" object is not available when it runs (the actual jenkinsfile is here: https://github.com/VirtoCommerce/vc-module-core/blob/eeee111fb33e12f93c9bf64988a193627dfb533a/Jenkinsfile ) Ideally I'd like to commit the file changed during the build (version file).

            Unassigned Unassigned
            alecharp Adrien Lecharpentier
            Votes:
            160 Vote for this issue
            Watchers:
            165 Start watching this issue

              Created:
              Updated: