Vincent's Weblog

Pelican and Jenkins


Mon 25 September 2023 By Vincent Lammens
Category: Misc
Tags: devops jenkins

I've always maintained my site using Jekyll, but it never worked quite well when I moved computers since I kept having dependency problems between one environment to the next. This is why I decided to look for an alternative.

I looked at a few options, like Wordpress, but I decided I wanted to keep a static site. After playing with Pelican a bit, I decided to migrate my site to Pelican.

Dealing with completely difirent URL's

URL's will be difirent, my solution is to add a (lot) of redirect statements in my webserver configuration file. Since I don't plan to move to another system soon, this should be fine. I did add a small note on the 404 page

Automatization with Jenkins

Since I was moving my site, I also decided to make use of the opportunity to automate the build process of my site. Jenkins allows me to automatically build publish the website using a small CI/CD pipeline. I've included the Jenkinsfile below:

Jenkinsfile:

pipeline {
  agent {
    docker {
      image 'python:3.8'
    }
  }
  stages {
    stage('setup') {
      steps {
        withEnv(["HOME=${env.WORKSPACE}"]) {
          sh 'python -m pip install --user --upgrade pip "pelican[markdown]"'
          sh 'python --version'
          sh 'python -m pelican --version'
        }
      }
    }
    stage('publish - web') {
      steps {
        withEnv(["HOME=${env.WORKSPACE}"]) {
          sh 'python -m pelican content -s publishconf.py'
        }
        sshPublisher(
          publishers: [
            sshPublisherDesc(
              configName: 'vincentlammens.be',
              sshRetry: [retries: 5, retryDelay: 10000],
              transfers: [
                sshTransfer(
                  remoteDirectory: '',
                  removePrefix: 'output/',
                  sourceFiles: 'output/**/*'
                )
              ]
            )
          ]
        )
      }
    }
  }

  post {
    always {
      cleanWs()
    }
  }
}