Configuration

Publications are configure in side the gitPublications.publications block.

gitPublications {
  publications {
    main {  (1)
      // Configuration goes here
    }
    pages { (2)
    }
  }
}
1 The org.ysb33r.git.publish plugin automatically creates a publication called main.
2 It is easy to add additional publications. In this is will result in a set of tasks named as gitPublishPagesPush etc.

There are a number of options that can be set in the the DSL.

gitPublications {
  publications {
    main {
      repoURI = 'https://gitlab.com/ysb33rOrg/aProject.git' (1)
      branch = 'pages' (2)
      fetchDepth = 3 (3)
      commitMessage = 'A future commit message' (4)
      repoDir = 'my/path' (5)

      preserve { (6)
        include '*foo*.txt'
      }

      contents { (7)
      }

      credentials { (8)
      }
    }
  }
}
1 The URI of the repository. Can be anything that can be lazy-converted to a URI. http(s) and ssh schemes are supported. Required.
2 Branch to publish to. Can be anything that can be lazy-converted to a string. Required.
3 Fetch depth. Optional.
4 Commit message. Can be anything that can be lazy-converted to a string. Required
5 Allows the default directory to be overwritten, but normally this is not necessary.
6 Configure which files should be preserved, even if they do not exist in the content specification. This is an instance of Gradle’s PatternFilterable.
7 Configure the sources of files to be synchronised to the repository directory. This is an instance of Gradle’s CopySpec which is configured here.
8 Credentials for accessing the remote repository. See next section for details.

Credentials

gitPublications {
  publications {
    main {
      credentials {
        httpUserNamePassword( 'user', project.gradleProperty('my.password')) (1)
        httpToken( grolifantOps.resolveProperty('gitlab.auth.token') ) (2)
        sshKey( 'anything-string-or-byte-array') (3)
        sshKeyWithPassphrase( 'anything-string-or-byte-array', 'my-passphrase') (4)
        sshKeyFromFile( project.provider('my.key') ) (5)
        sshKeyFromFileWithPassphrase(project.provider('my.key'), 'my-passphrase' ) (6)

        acceptAllSshHosts() (7)
        acceptAllGitlabSshHosts() (8)
        acceptAllGithubSshHosts() (9)
        acceptSshHost('my.host.example', 'ssh-rsa', 'anything-string-or-byte-array') (10)
      }
    }
  }
}
1 Configure HTTP access as a username and a password. Both parameters are lazy-evaluated to strings, so can be Provider, Callable, Closure etc.
2 Use a single auth token for access - typical for Github & Gitlab. The parameter is lazy-evaluated and the example uses Gorlifant’s resolveProperty to look for a Gradle property or a System property by the name of gitlab.auth.token. Failing that it will look for an environment variable called GITLAB_AUTH_TOKEN.
3 Provide an SSH key. It can be anything evaluating to a string or a byte[].
4 Provide an SSH key with a passphrase. The key can be anything evaluating to a string or a byte[]. The passphrase can be anything evaluating to a string.
5 Read the user key from a file. It must be a provider.
6 Read the user key from a file and unlock it with the passphrase. The file must be supplied via a provider. The passphrase can be anything evaluating to a string.
7 Accept all SSH host keys. Probably a security risk if you enable this, but it is useful for testing.
8 Accept only Gitlab SSH hosts.
9 Accept only Github SSH hosts.
10 This can be called multiple times to provide your own setup. It needs a host name, the encryption protocol and then the actual host public key.