/tutorials/basic/11-task-inputs-bonus/README.md

https://bitbucket.org/igtbdigital/concourse-ci · Markdown · 113 lines · 92 code · 21 blank · 0 comment · 0 complexity · 2cbcba50a3cc155c140c1637f9503d24 MD5 · raw file

  1. Task inputs
  2. ===========
  3. The pipelines in this tutorial show a task that imports resources and how it can access the files from those resources.
  4. http://concourse.ci/build-plans.html
  5. ```
  6. $ ./run.sh ls-abc-xyz
  7. ...
  8. running ls -opR .
  9. .:
  10. total 8
  11. drwxr-xr-x 3 vcap 4096 Apr 8 04:52 gist-abc/
  12. drwxr-xr-x 3 vcap 4096 Apr 8 04:53 gist-xyz/
  13. ./gist-abc:
  14. total 12
  15. -rw-r--r-- 1 vcap 8 Apr 8 04:52 a.md
  16. -rw-r--r-- 1 vcap 8 Apr 8 04:52 b.md
  17. -rw-r--r-- 1 vcap 8 Apr 8 04:52 c.md
  18. ./gist-xyz:
  19. total 12
  20. -rw-r--r-- 1 vcap 8 Apr 8 04:53 x.md
  21. -rw-r--r-- 1 vcap 8 Apr 8 04:53 y.md
  22. -rw-r--r-- 1 vcap 8 Apr 8 04:53 z.md
  23. ```
  24. The job `job-with-inputs` has a build plan that:
  25. - pulls in (`get`s) two resources (`type: git`) and
  26. - they are made available to the task `ls-abc-xyz`.
  27. The two `get` resources are described:
  28. ```yaml
  29. - { get: gist-abc, resource: resource-gist-a-b-c }
  30. - { get: gist-xyz, resource: resource-gist-x-y-z }
  31. ```
  32. They come from resources `resource-gist-a-b-c` and `resource-gist-x-y-z`; and are renamed `gist-abc` and `gist-xyz` respectively (their name within this particular job build plan).
  33. The purpose of the `ls-abc-xyz` task is to show how the resources `resource-gist-a-b-c` and `resource-gist-x-y-z` are passed through to subsequent steps.
  34. Looking at the output above you can see that the content of each resource are nested inside subfolders of the renamed build plan resources (`gist-abc` and `gist-xyz`).
  35. ### Explicit task inputs
  36. The task `ls-abc-xyz` declares explicitly that it wants both resources via its `inputs` configuration:
  37. ```yaml
  38. - task: ls-abc-xyz
  39. config:
  40. platform: linux
  41. image_resource:
  42. type: docker-image
  43. source: {repository: ubuntu}
  44. inputs:
  45. - name: gist-abc
  46. - name: gist-xyz
  47. run:
  48. path: ls
  49. args: ["-opR", "."]
  50. ```
  51. The `ls-abc-xyz` task explicitly shows that it has access to the files from the two resources (see output above). The files are in the root of the fetched repositories; but during the build plan they are now nested beneath a folder.
  52. We can demonstrate that a task only has access to resource inputs that it specifies by removing `gist-xyz` from the list of `inputs` above.
  53. ```
  54. $ run.sh ls-abc
  55. ...
  56. initializing
  57. running ls -opR .
  58. .:
  59. total 4
  60. drwxr-xr-x 3 vcap 4096 Apr 8 05:17 gist-abc/
  61. ./gist-abc:
  62. total 12
  63. -rw-r--r-- 1 vcap 8 Apr 8 05:17 a.md
  64. -rw-r--r-- 1 vcap 8 Apr 8 05:17 b.md
  65. -rw-r--r-- 1 vcap 8 Apr 8 05:17 c.md
  66. ```
  67. Bonus - pretty print via resource script
  68. ----------------------------------------
  69. ```
  70. $ ./run.sh pretty-ls
  71. ...
  72. initializing
  73. running bash pretty-ls/pretty_ls.sh .
  74. ./gist-abc
  75. ./gist-xyz
  76. ./pretty-ls
  77. ./gist-abc/a.md
  78. ./gist-abc/b.md
  79. ./gist-abc/c.md
  80. ./gist-xyz/x.md
  81. ./gist-xyz/y.md
  82. ./gist-xyz/z.md
  83. ./pretty-ls/pretty_ls.sh
  84. initializing
  85. running bash pretty-ls/pretty_ls.sh .
  86. ./gist-xyz
  87. ./pretty-ls
  88. ./gist-xyz/x.md
  89. ./gist-xyz/y.md
  90. ./gist-xyz/z.md
  91. ./pretty-ls/pretty_ls.sh
  92. ```