Override build steps

snapcraftctl is deprecated in favour of craftctl from core22 onwards. Please refer to Using craftctl tool for more information about the craftctl tool.

You can override and customise steps of a part’s lifecycle (pull, build, stage, and prime) using overrides; shell scripts directly sourced from snapcraft.yaml. These scripts are run with /bin/sh, which by default on Ubuntu is dash.

An override is declared with the following syntax:

parts:
  <part name>:
    override-<step name>: <shell script>

You can use a pipe on the first line to declare a multi-line script:

parts:
  <part name>:
    override-<step name>: |
      <multi-line>
      <shell script>

Overriding the pull step

This can be done by utilising the override-pull override. Its working directory is the part’s source directory in parts/<part name>/src/. In order to run the default pull step, call snapcraftctl pull from within the override itself.

Example

Let’s say you want to patch the source code of the part you’re pulling:

parts:
  foo:
    plugin: dump
    # ...
    override-pull: |
      snapcraftctl pull
      patch -p1 < $SNAPCRAFT_STAGE/my.patch

Overriding the build step

This can be done by utilising the override-build override. Its working directory is the part’s base build directory in parts/<part name>/build/. In order to run the default build step, call snapcraftctl build from within the override itself.

Example

Let’s say the default build/install process ends up installing files with absolute paths in them, which need to be fixed up to look inside the snap:

parts:
  foo:
    plugin: dump
    # ...
    override-build: |
      snapcraftctl build
      sed -i 's|/usr/bin|$SNAP/usr/bin|g' $SNAPCRAFT_PART_INSTALL/my-bin-artifact.sh

Overriding the stage step

This can be done by utilising the override-stage override. Its working directory is the staging area in stage/. In order to run the default stage step, call snapcraftctl stage from within the override itself.

Example

Let’s say you wanted to tweak a file installed by another part:

parts:
  foo:
    plugin: dump
    # ...
    after: [other-part]
    override-stage: |
      snapcraftctl stage
      sed -i 's|/usr/bin|$SNAP/usr/bin|g' other/parts/file

Overriding the prime step

This can be done by utilising the override-prime override. Its working directory is the primeing area in prime/. In order to run the default prime step, call snapcraftctl prime from within the override itself.

Example

Let’s say you wanted to compile gsetting schemas for the entire priming area

parts:
  foo:
    plugin: nil
    after: [all, other, parts]
    override-prime: |
      snapcraftctl prime
      glib-compile-schemas usr/share/glib-2.0/schemas

Last updated a month ago.