Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where should I set the skaffold.env to load my parameter to the skaffold.yaml? #9567

Open
IcewaveLJW opened this issue Nov 14, 2024 · 8 comments

Comments

@IcewaveLJW
Copy link

Expected behavior

skaffold.yaml can read the env variable WORKSPACE and worked as expexted.

Actual behavior

Error:parsing skaffold config: error parsing skaffold configuration file: parsing api version: yaml: line 13: did not find expected key

Information

  • Skaffold version: v2.13.2
  • Operating system: jenkins

I built like this

-ope/skaffold
  |_myservice
      |_skaffold.yaml
      |_skaffold.env
  • Contents of skaffold.yaml:
# Deprecated
apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: myservice
build:
  tagPolicy:
    gitCommit: {}
  local:
    push: true
    useDockerCLI: true
  artifacts:
    - image: dataservice
      context: '{{.WORKSPACE}}'/dist/
      docker:
        dockerfile: ../ope/docker/myservice/Dockerfile
deploy: ......
  • Contents of skaffold.env:
    WORKSPACE=/var/lib/jenkins/workspace/my_target_value

I saw the page here, https://skaffold.dev/docs/environment/env-file/, but seems it didn't work.

@idsulik
Copy link
Contributor

idsulik commented Nov 14, 2024

Try this one:
context: "${WORKSPACE}/dist/"

@IcewaveLJW
Copy link
Author

"${WORKSPACE}/dist/"

Thank you for quick replying, but no luck it still error like [2024-11-14T07:24:43.432Z] image "myservice" context "/${WORKSPACE}/dist/" does not exist

@idsulik
Copy link
Contributor

idsulik commented Nov 14, 2024

@IcewaveLJW it's a different error, have you passed the WORKSPACE environment? looks like you haven't

@IcewaveLJW
Copy link
Author

IcewaveLJW commented Nov 14, 2024

@IcewaveLJW it's a different error, have you passed the WORKSPACE environment? looks like you haven't

@idsulik I saw this on the page Skaffold will automatically load these variables into the environment before running any commands. Actually it's blur for me to pass a parameter in skaffold.yaml, here is my jenkins gvy which execute skaffold command,

 mkdir dist || true
 skaffold config set --global collect-metrics false
 skaffold build --profile=jenkins --default-repo=${REPO} --file-output=${env.SKAFFOLD_BUILD_ARTIFACTS} ${SH_SKAFFOLD_DRY_RUN} ${SKAFFOLD_OPTIONS}
 skaffold deploy --profile=${params.ENV} --build-artifacts=${env.SKAFFOLD_BUILD_ARTIFACTS} ${SKAFFOLD_OPTIONS}

, shall I do something here?

@idsulik
Copy link
Contributor

idsulik commented Nov 14, 2024

put this before the skaffold command:
echo "${WORKSPACE}/dist/" && ls "${WORKSPACE}/dist/"

@IcewaveLJW
Copy link
Author

Hi @idsulik I add these two new command
export WORKSPACE=${env.WORKSPACE} echo "${WORKSPACE}/dist/" && ls "${WORKSPACE}/dist/" beforeskaffold config set, it can show in the log but it still look like this in deployment process.

[2024-11-14T07:54:50.249Z] + export WORKSPACE=/var/lib/jenkins/workspace/mono_Skaffold
[2024-11-14T07:54:50.249Z] + echo /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] + ls /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] + skaffold config set --global collect-metrics false
[2024-11-14T07:54:50.249Z] set global value collect-metrics to false
[2024-11-14T07:54:50.249Z] + skaffold build --profile=jenkins --default-repo=xxx --file-output=skaffold-build.json --filename=xxx --namespace=xxx
[2024-11-14T07:54:50.504Z] image "myservice" context "/${WORKSPACE}/dist/" does not exist```

@idsulik
Copy link
Contributor

idsulik commented Nov 15, 2024

It seems to me that the context field doesn't support env templating https://skaffold.dev/docs/environment/templating/#list-of-fields-that-support-templating

@IcewaveLJW
Copy link
Author

It seems to me that the context field doesn't support env templating https://skaffold.dev/docs/environment/templating/#list-of-fields-that-support-templating

Thank you for checking, I mean does there some way can help me to deal with that? Why we need to use env variable here is that we may have lots of task running in the same time which be assigned different WORKSPACE so we have to transport it into yaml and make as absolute path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants