You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@community.apache.org by "rlenferink (via GitHub)" <gi...@apache.org> on 2023/04/01 09:55:24 UTC

[GitHub] [comdev-site] rlenferink commented on a diff in pull request #100: Use pinned version of Hugo

rlenferink commented on code in PR #100:
URL: https://github.com/apache/comdev-site/pull/100#discussion_r1155086940


##########
Jenkinsfile:
##########
@@ -56,10 +68,13 @@ pipeline {
         stage('Build') {
             steps {
                 script {
-                    sh 'for i in $(which -a hugo) ; do echo $i; $i version; done'
-                    sh 'hugo version'
-                    sh "hugo --destination ${env.OUT_DIR}"
-                    sh "${env.PAGEFIND_DIR}/bin/pagefind --source ${env.OUT_DIR}"
+                    withEnv(["PATH+HUGO=${env.HUGO_DIR}/bin", "PATH+PAGEFIND=${env.PAGEFIND_DIR}/bin"]) {

Review Comment:
   Without changing the PATH and calling `hugo`, the system default installation is used.
   
   Without changing the PATH and calling `${env.HUGO_DIR}/bin/hugo` the Hugo downloaded in the Jenkinsfile is used.
   
   With changing the PATH, and calling `hugo` the Hugo downloaded in the Jenkinsfile is used. The `PATH+TOOLNAME` will ensure the specified path is prepended to the PATH (so a first search location). See https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables 
   
   The following would be the same:
   
   ```groovy
   script {
       withEnv(["PATH+HUGO=${env.HUGO_DIR}/bin", "PATH+PAGEFIND=${env.PAGEFIND_DIR}/bin"]) {
           sh "hugo version"
           sh "pagefind --version"
   
           sh "hugo --destination ${env.OUT_DIR}"
           sh "pagefind --source ${env.OUT_DIR}"
       }
   }
   ```
   
   ```groovy
   script {
       sh "${env.HUGO_DIR}/bin/hugo version"
       sh "${env.PAGEFIND_DIR}/bin/pagefind --version"
   
       sh "${env.HUGO_DIR}/bin/hugo --destination ${env.OUT_DIR}"
       sh "${env.PAGEFIND_DIR}/bin/pagefind --source ${env.OUT_DIR}"
   }
   ```
   
   From a readability (and don't repeat yourself) perspective my preference is with the first code block (using `withEnv`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@community.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@community.apache.org
For additional commands, e-mail: dev-help@community.apache.org