6

I've got my Pipeline tasks as follows: (key one is Signing and aligning APK file(s) one).

enter image description here

When I am looking at logs of the build(s), apart from the Signing and aligning APK file(s) task logs there I also see Pre-job: Signing and aligning APK file(s) one and Post-job: ... ones (same as for Checkout).

However, I don't quite understand what those tasks are and how it appeared I have them in logs? I can't find any documentation related to that. And, correspondingly, considering there are the "Pre-job" tasks, if there is any way to define my own tasks executing before the Pipeline build starts?

enter image description here

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Agat
  • 4,577
  • 2
  • 34
  • 62

1 Answers1

9

A task can define pre- and post- steps. These will be added to the initialization phase of the job and to the cleanup stage. In the case of the signing task I can imagine it helps ensure the secrets are properly cleaned up when the job is finished.

Especially on a shared agent this can be important, because not cleaning up after the fact may lead to the secrets staying around on the agent and potential "capture" by other jobs running on the same machine.

You can dig into what these jobs do exactly by looking at the sources:

hlovdal
  • 26,565
  • 10
  • 94
  • 165
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks for the quick answer. So, does that mean, that for creating such "Pre-job" task I must create my own type of tasks and attach it to the Pipeline? (For instance, in case if I want some Powershell script to run on very very beginning of the Pipeline start). – Agat Oct 30 '18 at 14:24
  • 1
    Yes. That's the thing to do. – jessehouwing Oct 30 '18 at 14:30
  • Just to be sure I am not going to invent any bicycles (as long as I can't find any reasons why none would want to run any initial Powershell scripts before any other tasks so far), might you be aware of any handy (existing) tool/way of doing that (with PowerShell or other similar method)? – Agat Oct 30 '18 at 17:53
  • 1
    In theory you could add this feature to an existing 'run powershell' task. As far as I know it's not in there by default. It may be worth a pull request to Azure-Pipelines-tasks. – jessehouwing Oct 30 '18 at 18:55
  • Well, in general, it doesn't look like ideal architecture though, as visually that (such) task(s) are quite specific and aimed to be executed "at place" (where they are in the tasks list), and the issue is Azure DevOps just don't have "pre" and "post" section. (It would be ok just to have a common flow as it is now, but you just can't start any task until the sources are pulled from the repository). – Agat Oct 30 '18 at 20:51
  • @Agat out of curiosity, did you end up creating such a task for executing PowerShell as a pre-job step? I presently need that functionality as well. – Kamuela Franco Mar 15 '21 at 15:02
  • @KamuelaFranco an example: https://github.com/jessehouwing/azure-pipelines-tfvc-tasks/tree/main/tf-vc-dontsync/v2 – jessehouwing Apr 23 '21 at 07:14