Jenkins


Jenkins is a tool for automating build, testing and deployment of projects. To acquire access to it create a ticket in helpdesk containing:

  • login (sXXXXXX) of the project lead
  • project name containing only letters, numbers - and _
  • logins of project members

The system is available at https://jenkins.wmi.amu.edu.pl. Domain credentials are used (like in the laboratories).

Git Configuration

It's possible to link Jenkins with our Git system. In order to achieve this both Jenkins and the repository has to be configured.

Jenkins configuration

  • open the semester folder (e.g. 2019Z) and open your project -> Configure
  • Gogs Webhook
    • Use Gogs secret
    • Secret: very long string
  • Build Triggers
    • Build when a change is published to Gogs
  • Pipeline
    • Definition: Pipeline script from SCM
    • SCM: Git
    • Repository URL: adres SSH repozytorium (e.g. git@git.wmi.amu.edu.pl:s123456/project.git)
    • Credentials: git (SSH read-only access for git.wmi.amu.edu.pl)
    • Repository browser: gogs
    • URL: HTTPS repository address (without the ending '.git') (e.g. https://git.wmi.amu.edu.pl/s123456/project)
    • Lightweight checkout
    • Save

Git repository configuration

In the Git repository configuration:

  • Settings -> Webhooks -> Add Webhook -> Gogs
  • Deploy Keys -> Add Deploy Key
    • Title: jenkins
    • Content: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOuVvhUjr+UosOx3IEBUi0IfV8Erv2OL3Er5pUHbjxNo

Usage of SSH from the pipeline

It's possible to add SSH connection support from the Jenkins pipeline. A common usage would be copying of a built and tested application version, and performing actions on the remote server, for example restarting the WWW service.

The public SSH key used by Jenkins for external SSH connections:

ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKRso2eJ1wXHqD83Ii8Qem0kDWY5sCFVS6OczBpOPT+66nvOt5Z0VNajjZLkA5BXh0ZoZ+RqDQdi4JMndPvcEwY= jenkins-ssh-external

Requesting SSH for a project

To activate the SSH function create a ticket in helpdesk containing:

  • Jenkins project name
  • SSH host name
  • SSH user name (it has to trust the SSH key specified above)
  • absolute path to the directory used as the work directory over SSH

You will receive a SSH configuration name that will be required in the project Jenkinsfile in accordance to the codumentation.

An example Jenkinsfile implementation

Copying files over SSH

The section below will transfer build.tar.gz to the target SSH server:

stage('SSH-publish') {
    steps {
        sshPublisher(
            continueOnError: false, 
            failOnError: true,
            publishers: [
                sshPublisherDesc(
                configName: "CONFIGURATION_NAME_RECEIVED_FROM_HELPDESK",
                transfers: [sshTransfer(sourceFiles: 'build.tar.gz')],
                verbose: true
                )
            ]
        )
    }
}

Performing remote actions over SSH

The section below will delete build.tar.gz on the remote SSH server:

stage('SSH-exec') {
    steps {
        sshPublisher(
            continueOnError: false, 
            failOnError: true,
            publishers: [
                sshPublisherDesc(
                configName: "CONFIGURATION_NAME_RECEIVED_FROM_HELPDESK",
                transfers: [sshTransfer(execCommand: 'rm build.tar.gz')],
                verbose: true
                )
            ]
        )
    }
}