Setting Environment variables Using Factories
Using Factories, do i have an option to use variables/attributes as environment variables. For example - during Factory creation - i would like to have a variable (say ticketID) as an attribute/some parameter in factory configuration json and would use the same inside my workspace as environment variable. Is there a possibility to achieve this ?
Version: Eclipse Che 5.8.0 Docker 1.13.0
@mvidhya86 currently, the only way to achieve what you are trying to achieve is to use a dockerfile rather than image in a recipe object. In your factory.json it will look like:
"recipe": {
"type": "dockerfile",
"content": "FROM eclipse/ubuntu_jdk8\nENV key value\n",
"contentType": "text/x-dockerfile"
}
@eivantsov - thanks for your comments. In my case - these values are dynamic.
The case here is - if the Factory url has some additions like - http://servername:8080/dashboard/#/factory?id=1234
From the factory url - retrieve id and its value and use it like $key : $value in factory configuration (json)
And this has to be visible inside my workspace (as env variable or by other means).
Does Che provide such options ?
If you update your factory.json the way I proposed, you will have envs in a workspace. However, their values will be static.
That means are there no means for passing arguments to the factory url which are used "as variables" in the factory json? In other words, can the same factory be used to create workspaces which are very similar one to another (ex: just working on a different jira ticket) ?
No, there's no such functionality.
What is the alternative? Create a workspace from teh factory and later use an API to set variables in the workspace? BTW, is there such a concept as "workspace variables"? or just the linux environment variables?
All env vars that end up in a workspace container are added with Docker. But in a container, they are just like linux envvars
Hi @mvidhya86 . You mentioned your use case around having a different factory per jira tickets. In this case, that means you would have a system, where you can define a "Factory template" and then depending on the jira ticket, you'll create a new factory based on that template. It would be when you create the factory that you replace the parameters from the template. As a result, you'll have a different factory per jira tickets.
It's exactly what Codenvy is providing with the JIRA plugin: https://codenvy.io/docs/integration-guide/issue-management/index.html
But that would result in many factories. In the end I want to have one workspace per ticket. ...and somewhere in the workspace I need to store the ticket number so I can navigate back, create automatic commit messages, etc.
On Apr 27, 2017 6:11 PM, "Stévan Le Meur" [email protected] wrote:
Hi @mvidhya86 https://github.com/mvidhya86 . You mentioned your use case around having a different factory per jira tickets. In this case, that means you would have a system, where you can define a "Factory template" and then depending on the jira ticket, you'll create a new factory based on that template. It would be when you create the factory that you replace the parameters from the template. As a result, you'll have a different factory per jira tickets.
It's exactly what Codenvy is providing with the JIRA plugin: https://codenvy.io/docs/integration-guide/issue-management/index.html
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/che/issues/4935#issuecomment-297763230, or mute the thread https://github.com/notifications/unsubscribe-auth/AC0NeBjSVTFijkDCLK5Qtu1bBgRokDtVks5r0L47gaJpZM4NJxee .
I think you may store this info in machine attributes too:
"dev-machine": {
"attributes": {
"memoryLimitBytes": "2147483648",
"new": "smth"
}
}
I am not sure this solve your problem though.
@eivantsov - If we store the variable in machine attributes - how do i retrieve inside my workspace ?
@mvidhya86 you may use curl in a terminal, for example. Can you elaborate on how exactly you need to get those?
Yes, considering that i updated the workspace configuration with new attribute dev-machine": { "attributes": { "memoryLimitBytes": "2147483648", "tempid": "test" },
After opening the workspace - if i create a new command (command line - specify syntax) to retrieve this custom attribute value, what should i use in curl.
Smth like this should work for you:
curl -s http://$IP:8080/api/workspace/$ws-id | jq .attributes | grep tempid | awk '{print $2}' | sed 's/\"//g'
However, you may need jq installed in your stack if you are going to call this API from within a workspace. And replace $ws-id with an actual workspace ID.
@mvidhya86 did my suggestion work for you?
@eivantsov not related directly to this issue but just wanted to say thanks as your suggestion of using attributes in combination with curl/jq saved us a lot of manual work #4800
@davidwindell good to know. @mvidhya86 i am closing the issue. Feel free to reopen if you have further questions.