Can I get variable value during the optimization JuMP.value?

I want to get variables’ value and use it in objective function during the optimization.
When I try JuMP.value(), it shows NoOptimizer(). But the Optimizer is defined in the main function.
Is there anyway that I can get variables’ value in objective function during the optimization?

Thanks a lot!

Please read Please read: make it easier to help you and provide a minimum working example.

Thanks for reminding this! I will update my question.